[Bf-blender-cvs] [8c7503726df] readfile-rework-refcount-handling: readfile: Quick experiment with refcounting moved to libquery.

Bastien Montagne noreply at git.blender.org
Wed Feb 5 17:01:10 CET 2020


Commit: 8c7503726df916ea74d94b853960d983bee80ccb
Author: Bastien Montagne
Date:   Mon Feb 3 10:41:56 2020 +0100
Branches: readfile-rework-refcount-handling
https://developer.blender.org/rB8c7503726df916ea74d94b853960d983bee80ccb

readfile: Quick experiment with refcounting moved to libquery.

Having that extra ID users handling at readfile level, besides generic
one ensured by libquery, has been something bothering me for a long time
(had to fix my share of bugs due to mismatches between those two areas).

Further more, work on undo speedup will require even more complex ID
refcount management if we want to keep it in readfile.c area.

So idea is instead to generalize what we did for linked data already
when undoing: recompute properly usercount numbers after liblink step,
for all IDs.

Note that extra time required here is neglectable in a whole .blend file
reading (few extra milliseconds when loading a full production scene
e.g.).

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

M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/blenloader/intern/readfile.c

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

diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 62173393256..4c1d34292dc 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -364,16 +364,6 @@ static void setup_app_data(bContext *C,
     /* TODO(sergey): Can this be also move above? */
     RE_FreeAllPersistentData();
   }
-
-  if (mode == LOAD_UNDO) {
-    /* In undo/redo case, we do a whole lot of magic tricks to avoid having to re-read linked
-     * data-blocks from libraries (since those are not supposed to change). Unfortunately, that
-     * means that we do not reset their user count, however we do increase that one when doing
-     * lib_link on local IDs using linked ones.
-     * There is no real way to predict amount of changes here, so we have to fully redo
-     * refcounting . */
-    BKE_main_id_refcount_recompute(bmain, true);
-  }
 }
 
 static void setup_app_blend_file_data(bContext *C,
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index bc3ddbe9bd3..daa2c26d881 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1792,7 +1792,7 @@ static void *newlibadr_us(FileData *fd, const void *lib, const void *adr)
 {
   ID *id = newlibadr(fd, lib, adr);
 
-  id_us_plus_no_lib(id);
+  /* id_us_plus_no_lib(id); */
 
   return id;
 }
@@ -1808,7 +1808,7 @@ static void *newlibadr_real_us(FileData *fd, const void *lib, const void *adr)
 {
   ID *id = newlibadr(fd, lib, adr);
 
-  id_us_ensure_real(id);
+  /* id_us_ensure_real(id); */
 
   return id;
 }
@@ -9395,7 +9395,7 @@ static void do_versions_after_linking(Main *main, ReportList *reports)
 /* -------------------------------------------------------------------- */
 /** \name Read Library Data Block (all)
  * \{ */
-
+#include "PIL_time_utildefines.h"
 static void lib_link_all(FileData *fd, Main *bmain)
 {
   ID *id;
@@ -9537,6 +9537,10 @@ static void lib_link_all(FileData *fd, Main *bmain)
   }
   FOREACH_MAIN_ID_END;
 
+  TIMEIT_START(readfile_refcount_recomp);
+  BKE_main_id_refcount_recompute(bmain, false);
+  TIMEIT_END(readfile_refcount_recomp);
+
   /* Check for possible cycles in scenes' 'set' background property. */
   lib_link_scenes_check_set(bmain);



More information about the Bf-blender-cvs mailing list