Page MenuHome

Optimized per-datablock global undo
Open, NormalPublic

"Yellow Medal" token, awarded by amonpaike."Like" token, awarded by d.viagi."Burninate" token, awarded by crantisz."Burninate" token, awarded by mauriciomarinho."Love" token, awarded by razgriz286."Burninate" token, awarded by lordodin."Love" token, awarded by dgsantana."Love" token, awarded by jsm."Burninate" token, awarded by Plyro."Yellow Medal" token, awarded by Way."Love" token, awarded by dpdp."Love" token, awarded by michaelknubben."Love" token, awarded by Frozen_Death_Knight."Love" token, awarded by Krayzmond."Love" token, awarded by Tetone."Love" token, awarded by symstract."Love" token, awarded by koloved."Like" token, awarded by Scaredyfish."100" token, awarded by Zino."Like" token, awarded by billreynish."Love" token, awarded by lcs_cavalheiro."Like" token, awarded by zanqdo."Love" token, awarded by 0o00o0oo."Like" token, awarded by DaPaulus."Love" token, awarded by verbal007."Like" token, awarded by aliasguru."Love" token, awarded by juang3d.
Assigned To
Authored By


Global undo is slow on scenes with many objects. A big reason is that undo writes and reads all datablocks in the file (except from linked libraries). If we can only handle the ones that actually changed, performance would be much improved in common scenarios.

This proposal outlines how to achieve this in 3 incremental steps. Only 1 or 2 of these steps would already provide a significant speedup.

At the time of writing there is no concrete plan to implement this, but I've had this idea for a while and it seemed useful to write down in case someone likes to pick it up.

1. Read only changed datablocks

Linked library datablocks are already preserved on undo pop. We can do the same thing for all non-changed datablocks, and only read the changed ones.

We can detect which datablocks were changed by checking that their diff is empty. Addition and removal of datablocks also needs to be detected. We need to be careful to exclude runtime data like LIB_TAG_DOIT from writing, to avoid detecting too many datablocks as changed. Most changes to runtime data go along with an actual change to the datablock though.

Since unchanged datablocks may point do changed datablocks, we need to reload datablocks in the exact same memory location. We can safely assume the required memory size stays the same, because if it didn't those other datablocks' pointers would be changed as well. In principle other datablocks should not point to anything but the datablock itself, but there may be exceptions that need to be taken care of.

Main fields other than datablock lists may need some attention too.

2. Optimize post undo/redo updates

The most expensive update is likely the dependency graph rebuild. We can detect if any depsgraph rebuild was performed between undo pushes, and if so mark that undo step as needing a depsgraph rebuild. This means the undo step is no more expensive than the associated operation.

This requires the dependency graph to be preserved through undo in scene datablocks, similar to how images preserve image buffers. This would then also preserve GPU data stored in the dependency graph. If the dependency graph supports partial rebuilds in the future, that could be taken advantage of.

There may be other expensive updates, to be revealed by profiling.

3. Write only changed datablocks

While undo/redo is usually the most expensive, the undo push that happens after each operation also slows down as scene complexity increases. If we know which datablocks changed, we can only save & diff those.

This could be deduced from dependency graph update tags. However there are likely still many operations where tags are missing. If it is not done correctly, then instead of a missing refresh there is a more serious bug of not undoing all changes. So this needs verification throughout the Blender code for correct tagging, before it can be enabled.

Debug builds could verify correctness by testing the diff is empty whenever there was no tag.



Event Timeline

Brecht Van Lommel (brecht) triaged this task as Normal priority.
Way awarded a token.Jun 4 2019, 4:07 AM