Commit: 09da47b67a28aa3dd814b5c7d309d3481b39e77c
Author: Sergey Sharybin
Date:   Wed Apr 25 14:58:19 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB09da47b67a28aa3dd814b5c7d309d3481b39e77c

Depsgraph: Avoid hash lookup for every evaluated scene query

Cache pointer to evaluated scene datablock on relations build time,
that pointer never changes after that.

===================================================================

M       source/blender/depsgraph/intern/depsgraph.cc
M       source/blender/depsgraph/intern/depsgraph.h
M       source/blender/depsgraph/intern/depsgraph_build.cc
M       source/blender/depsgraph/intern/depsgraph_query.cc

===================================================================

diff --git a/source/blender/depsgraph/intern/depsgraph.cc 
b/source/blender/depsgraph/intern/depsgraph.cc
index c90279b0e90..a4aff826af4 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -102,7 +102,8 @@ Depsgraph::Depsgraph(Scene *scene,
     scene(scene),
     view_layer(view_layer),
     mode(mode),
-    ctime(BKE_scene_frame_get(scene))
+    ctime(BKE_scene_frame_get(scene)),
+    scene_cow(NULL)
 {
        BLI_spin_init(&lock);
        id_hash = BLI_ghash_ptr_new("Depsgraph id hash");
diff --git a/source/blender/depsgraph/intern/depsgraph.h 
b/source/blender/depsgraph/intern/depsgraph.h
index e10f7d5b115..284dc28031b 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -197,6 +197,11 @@ struct Depsgraph {
 
        /* Time at which dependency graph is being or was last evaluated. */
        float ctime;
+
+       /* Evaluated version of datablocks we access a lot.
+        * Stored here to save us form doing hash lookup.
+        */
+       Scene *scene_cow;
 };
 
 }  // namespace DEG
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc 
b/source/blender/depsgraph/intern/depsgraph_build.cc
index ecd3d5361f8..0a958fa67d3 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build.cc
@@ -260,6 +260,9 @@ void DEG_graph_build_from_view_layer(Depsgraph *graph,
        /* Relations are up to date. */
        deg_graph->need_update = false;
 
+       /* Store pointers to commonly used valuated datablocks. */
+       deg_graph->scene_cow = (Scene 
*)deg_graph->get_cow_id(&deg_graph->scene->id);
+
        if (need_on_visible_update) {
                DEG_graph_on_visible_update(bmain, graph);
        }
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc 
b/source/blender/depsgraph/intern/depsgraph_query.cc
index 63eb1f18281..8f4bf2d082e 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query.cc
@@ -105,9 +105,7 @@ Scene *DEG_get_evaluated_scene(const Depsgraph *graph)
 {
        const DEG::Depsgraph *deg_graph =
                reinterpret_cast<const DEG::Depsgraph *>(graph);
-       Scene *scene_orig = deg_graph->scene;
-       Scene *scene_cow =
-               reinterpret_cast<Scene 
*>(deg_graph->get_cow_id(&scene_orig->id));
+       Scene *scene_cow = deg_graph->scene_cow;
        /* TODO(sergey): Shall we expand datablock here? Or is it OK to assume
         * that calleer is OK with just a pointer in case scene is not up[dated
         * yet?

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to