Outliner ID remapping performance #94185

Closed
opened 2021-12-17 11:34:39 +01:00 by Jeroen Bakker · 10 comments
Member

ID remapping is the mechanism to replace id pointers with other values. This is used in different scenarios like file reading, removing id blocks, resyncing. Remapping in the outliner is slow. Reason is that per ID it goes over all tree elements (treestore).

Outliner has a reverse lookup, but isn't usable for cases where you only have a part of its key.

space_outliner->runtime->treehash can contain a GHash.
The key of the treehash is an encoding of:

  • TreeStoreElem.type
  • TreeStoreElem.nr
  • TreeStoreElem.id

Due to its encoding it is only possible to do a reverse lookup when all 3 elements are known. nr seems to be the index of a modifier it points to. Type is very divers and seems to implement multiple indexing in a single ghash.

Alternative 1: remapping user data

Use a custom reverse lookup for remapping. Current codebase would only benefit of having a reverse lookup during remapping. Adding a user data to the remapping process needs many changes in the ID management control flow.

Current control flow

For each ID:
  for each screen:
    for each area:
      for each space:
        perform space remap

In this situation the remapping should be stored on the highest level and requires a lookup to the user data along the way.
This lookup can be eliminated by adding a remap process init and free function or by lazy initialization with a free function.

Alternative 2: Bulk test

A hacky alternative is to use the space_outliner->runtime->treehash and loop over all possible TreeStoreElem.type. This leads to unmaintainable code and many lookups that doesn't count.

The number of searches could be reduced by keeping track of each used TreeStoreElem.type per IDType.
This data still needs to be stored in the space data and would still require a free function as we don't want to keep this data around.

Alternative 3: Remap multiple.

Create arrays containing all the remappings that needs to be done. In stead of doing them one by one do perform them for the whole array at once.

This would need a large refactoring of existing code (delete, loading, resync etc) with a lot of unknows. To mitigate the complexity we could support both (single remap and multiple remap. And migrate per functionality, but that has the possibility that the current implementation will never be phased out.

Alternative N: ...

Placeholder for future ideas.

Conclusion

Conclusion so far is that there might not be an easy clean solution. Personally would push for the remap multiple, but it has risks that I cannot oversee without doing some experiments.

ID remapping is the mechanism to replace id pointers with other values. This is used in different scenarios like file reading, removing id blocks, resyncing. Remapping in the outliner is slow. Reason is that per ID it goes over all tree elements (treestore). Outliner has a reverse lookup, but isn't usable for cases where you only have a part of its key. space_outliner->runtime->treehash can contain a GHash. The key of the treehash is an encoding of: * TreeStoreElem.type * TreeStoreElem.nr * TreeStoreElem.id Due to its encoding it is only possible to do a reverse lookup when all 3 elements are known. nr seems to be the index of a modifier it points to. Type is very divers and seems to implement multiple indexing in a single ghash. ## Alternative 1: remapping user data Use a custom reverse lookup for remapping. Current codebase would only benefit of having a reverse lookup during remapping. Adding a user data to the remapping process needs many changes in the ID management control flow. Current control flow ``` For each ID: for each screen: for each area: for each space: perform space remap ``` In this situation the remapping should be stored on the highest level and requires a lookup to the user data along the way. This lookup can be eliminated by adding a remap process init and free function or by lazy initialization with a free function. ## Alternative 2: Bulk test A hacky alternative is to use the space_outliner->runtime->treehash and loop over all possible `TreeStoreElem.type`. This leads to unmaintainable code and many lookups that doesn't count. The number of searches could be reduced by keeping track of each used TreeStoreElem.type per IDType. This data still needs to be stored in the space data and would still require a free function as we don't want to keep this data around. ## Alternative 3: Remap multiple. Create arrays containing all the remappings that needs to be done. In stead of doing them one by one do perform them for the whole array at once. This would need a large refactoring of existing code (delete, loading, resync etc) with a lot of unknows. To mitigate the complexity we could support both (single remap and multiple remap. And migrate per functionality, but that has the possibility that the current implementation will never be phased out. ## Alternative N: ... Placeholder for future ideas. # Conclusion Conclusion so far is that there might not be an easy clean solution. Personally would push for the remap multiple, but it has risks that I cannot oversee without doing some experiments.
Jeroen Bakker self-assigned this 2021-12-17 11:34:39 +01:00
Author
Member

Added subscribers: @Jeroen-Bakker, @mont29, @brecht, @dfelinto

Added subscribers: @Jeroen-Bakker, @mont29, @brecht, @dfelinto
Author
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Just noting (though a bit OT) that it also spawns popups for all selected IDs (all on top of each other), see #93814 (Outliner: Remap Users spawns multiple dialogs on top of each other)

Just noting (though a bit OT) that it also spawns popups for all selected IDs (all on top of each other), see #93814 (Outliner: Remap Users spawns multiple dialogs on top of each other)
Jeroen Bakker changed title from Outliner remapping to Outliner ID remapping 2021-12-17 13:37:14 +01:00
Jeroen Bakker changed title from Outliner ID remapping to Outliner ID remapping performance 2021-12-17 13:37:21 +01:00

Why is it remapping pointers in the outliner tree, instead of rebuilding the tree? Is it to preserve the tree expand/collapse state for the remapped data, because it's somehow really noticeable when you use the remap operation in the outliner?

At least as far as I know, for most operators that edit datablock relations we just rebuild the tree, it's not obvious to me why we do something else here.

Also makes me wonder if resync could do something similar to undo and preserve datablock memory locations, so we don't even have to remap pointers.

Why is it remapping pointers in the outliner tree, instead of rebuilding the tree? Is it to preserve the tree expand/collapse state for the remapped data, because it's somehow really noticeable when you use the remap operation in the outliner? At least as far as I know, for most operators that edit datablock relations we just rebuild the tree, it's not obvious to me why we do something else here. Also makes me wonder if resync could do something similar to undo and preserve datablock memory locations, so we don't even have to remap pointers.

Added subscriber: @Garek

Added subscriber: @Garek
Jeroen Bakker removed their assignment 2021-12-17 15:00:01 +01:00

Added subscriber: @GeorgiaPacific

Added subscriber: @GeorgiaPacific

This issue was referenced by a21bca0e20

This issue was referenced by a21bca0e20a05177f514e703bd99a929d5349034

This issue was referenced by 948211679f

This issue was referenced by 948211679f2a0681421160be0d3b90f507bc0be7
Author
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Jeroen Bakker self-assigned this 2022-01-28 09:50:46 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#94185
No description provided.