Fix ViewLayers cache building #73411

Open
opened 2020-01-26 17:50:23 +01:00 by Bastien Montagne · 18 comments

Currently, ViewLayers' collection and objects cache is rebuilt way too much (it can be thousands of time during a single edit action in a relatively heavy scene).

Proposal

Use a lazy update approach:

  • Code changing the the data only tags the relevant view layers' caches to be updated.
  • Code actually using those caches is responsible to call a new 'ensure()' callback first, which will check those flags and rebuild the cache as needed.

We can stay fairly general (tag a whole cache as dirty, and just fully rebuild it then when required), or be more specific by tagging every ID that changed, and then cache rebuilding code could only update the parts that need it.

Profiling on worst-case scenarii should tell us if high level of granularity is really needed here (worst case would be a viewlayer with many collections and objects).

Another possibility would be to add an API to actually update the needed parts of the caches on the fly (called from code modifying the related IDs relationships), but this is likely more complex to get working.

Note: Thread safety should not be an issue here, at least there is none at all in current code…

Currently, ViewLayers' collection and objects cache is rebuilt way too much (it can be thousands of time during a single edit action in a relatively heavy scene). ## Proposal Use a lazy update approach: * Code changing the the data only tags the relevant view layers' caches to be updated. * Code actually using those caches is responsible to call a new 'ensure()' callback first, which will check those flags and rebuild the cache as needed. We can stay fairly general (tag a whole cache as dirty, and just fully rebuild it then when required), or be more specific by tagging every ID that changed, and then cache rebuilding code could only update the parts that need it. Profiling on worst-case scenarii should tell us if high level of granularity is really needed here (worst case would be a viewlayer with many collections and objects). Another possibility would be to add an API to actually update the needed parts of the caches on the fly (called from code modifying the related IDs relationships), but this is likely more complex to get working. *Note: Thread safety should not be an issue here, at least there is none at all in current code…*
Author
Owner

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

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

Added subscriber: @mont29

Added subscriber: @mont29

Added subscriber: @rwman

Added subscriber: @rwman

Added subscriber: @SamGreen

Added subscriber: @SamGreen

Added subscriber: @Moult

Added subscriber: @Moult
Member

Added subscriber: @Imaginer

Added subscriber: @Imaginer

Added subscriber: @Dangry

Added subscriber: @Dangry

Added subscriber: @ahmed.hindy96

Added subscriber: @ahmed.hindy96
Member

Added subscriber: @Jeroen-Bakker

Added subscriber: @Jeroen-Bakker

Added subscriber: @monique

Added subscriber: @monique

Added subscriber: @aras_p

Added subscriber: @aras_p

For people who aren't super familiar with blender codebase but might want to try doing this (asking for a friend :)) -- is the idea that all the work currently done by the likes of BKE_main_collection_sync, BKE_scene_collection_sync, BKE_layer_collection_sync and similar would merely mark something as "yo, this needs a sync at some point", and then the actual resync happens once it's needed (e.g. when BKE_view_layer_base_find is called)?

And then part of the work would be finding various loops in the codebase that right now do something like

for N objects:
    do something that changes view layer things
    immediately find view layer base for said object

and change them to a pattern like:

for N objects:
    do something that changes view layer things
for N objects:
   find view layer base for the object

since that would turn N heavy operations into 1 heavy operation?

Or am I misunderstanding the issue completely :)

For people who aren't super familiar with blender codebase but might want to try doing this (asking for a friend :)) -- is the idea that all the work currently done by the likes of `BKE_main_collection_sync`, `BKE_scene_collection_sync`, `BKE_layer_collection_sync` and similar would merely mark something as "yo, this needs a sync at some point", and then the actual resync happens once it's needed (e.g. when `BKE_view_layer_base_find` is called)? And then part of the work would be finding various loops in the codebase that right now do something like ``` for N objects: do something that changes view layer things immediately find view layer base for said object ``` and change them to a pattern like: ``` for N objects: do something that changes view layer things for N objects: find view layer base for the object ``` since that would turn N heavy operations into 1 heavy operation? Or am I misunderstanding the issue completely :)
Author
Owner

@aras_p that is the idea yes. Most (if not all) of the code in BKE_main_collection_sync and similar would then move to the new 'lazy' on-demand syncing code (the ensure() callback in task above).

@aras_p that is the idea yes. Most (if not all) of the code in `BKE_main_collection_sync` and similar would then move to the new 'lazy' on-demand syncing code (the `ensure()` callback in task above).
Monique Dewanchand self-assigned this 2022-08-27 23:09:28 +02:00

This issue was referenced by 17501c146e

This issue was referenced by 17501c146edc4af8a5e04565dc4d0b30ed5c5323

Added subscriber: @AlexeyAdamitsky

Added subscriber: @AlexeyAdamitsky

This issue was referenced by 23276bcc37

This issue was referenced by 23276bcc37acc54f1e1814abdf482a432523c3a6

This issue was referenced by 68589a31eb

This issue was referenced by 68589a31ebfb79165f99a979357d237e5413e904

This issue was referenced by f017fdecef

This issue was referenced by f017fdecefc41ffe796ccfe9a1cb05772a7ad315
Philipp Oeser removed the
Interest
Core
label 2023-02-09 14:43:15 +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
12 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#73411
No description provided.