Currently when evaluating an action the fcurves are evaluated one by one, and does not keep the previous state so it re-evaluates for every curve.
Typically fcurves are ordered (or where not could be ordered) that you are already near the RNA path of the previous evaluated fcurve. When using this concept we could remove rna path resolve partially or completely in most cases. This will reduce the 'steps' to evaluate rna paths, but also allows for optimizations on branching and caching.
T77124: [WIP] Cache `RNA_path_resolve` in dependency graph demonstrates that we can extract some essential bits from an RNA_path_resolve and transfer it to other IDBlocks/types. The patch is limited as it still walks from the start of the IDBlock to the RNAProperty, what still contains overhead (memory creation, memcpy, hashing, etc)
Phases of the implementation
- Phase 1: Keep track of the last rna_resolved_path and use this when the rna_path is still the same.
- Phase 2: Combine array indexes so we just trigger RNA updates once.
- Phase 3: Find the shortest path from the last RNA resolved path to the next resolved rna path.
Current implementation reduces performance as it reaches to multiple areas of blender in the internal loop. This reduces the branch prediction, d-cache and i-cache of the CPU. We could reduce the inner loop and needed branches to perform the animsys update in multiple phases. Some part of the code is currently done twice (during read and write)
Depsgraph Build time
- find curves that needs to be evaluated this list doesn't change that much and could be stored in an animsys_runtime
- order the curves based on the RNA Property type.
- calculate evaluation instructions to process these curves.
Depsgraph Evaluation time
- pre-calculate the fcurves and store them in a array (one loop)
- don't find original ID in the inner loop, but place it in the outer loop
- go over the evaluate instructions and store the correct fcurve value and link it to the correct RNAProperty (don't store yet)
- do the same for the original ID.
- go over the value->property list and perform the updates.
The above is focussed on bActions of the AnimSystem. Drivers seems to be evaluated one by one, we should see if we can group them together based on the target.
Still need to look into the overhead of fcurves in the NlaStrip. (id is the object so it could also benefit from the above.).