[Bf-blender-cvs] [7733bd5] master: PyAPI: avoid scanning all addons on startup

Campbell Barton noreply at git.blender.org
Fri Jan 23 06:39:13 CET 2015


Commit: 7733bd5efc8e90f85385e5a93066158a17b14a93
Author: Campbell Barton
Date:   Fri Jan 23 16:20:37 2015 +1100
Branches: master
https://developer.blender.org/rB7733bd5efc8e90f85385e5a93066158a17b14a93

PyAPI: avoid scanning all addons on startup

Gives small speedup

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

M	release/scripts/modules/addon_utils.py
M	release/scripts/modules/bpy/utils.py

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

diff --git a/release/scripts/modules/addon_utils.py b/release/scripts/modules/addon_utils.py
index d236a59..9ec6d24 100644
--- a/release/scripts/modules/addon_utils.py
+++ b/release/scripts/modules/addon_utils.py
@@ -36,6 +36,15 @@ error_encoding = False
 addons_fake_modules = {}
 
 
+# called only once at startup, avoids calling 'reset_all', correct but slower.
+def _initialize():
+    path_list = paths()
+    for path in path_list:
+        _bpy.utils._sys_path_ensure(path)
+    for addon in _user_preferences.addons:
+        enable(addon.module)
+
+
 def paths():
     # RELEASE SCRIPTS: official scripts distributed in Blender releases
     addon_paths = _bpy.utils.script_paths("addons")
@@ -182,14 +191,16 @@ def modules_refresh(module_cache=addons_fake_modules):
 
 
 def modules(module_cache=addons_fake_modules, refresh=True):
-    if refresh:
+    if refresh or ((module_cache is addons_fake_modules) and modules._is_first):
         modules_refresh(module_cache)
+        modules._is_first = False
 
     mod_list = list(module_cache.values())
     mod_list.sort(key=lambda mod: (mod.bl_info["category"],
                                    mod.bl_info["name"],
                                    ))
     return mod_list
+modules._is_first = True
 
 
 def check(module_name):
diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py
index dd771af..bf882db 100644
--- a/release/scripts/modules/bpy/utils.py
+++ b/release/scripts/modules/bpy/utils.py
@@ -244,7 +244,14 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
                         test_register(mod)
 
     # deal with addons separately
-    _addon_utils.reset_all(reload_scripts)
+    _initialize = getattr(_addon_utils, "_initialize", None)
+    if _initialize is not None:
+        # first time, use fast-path
+        _initialize()
+        del _addon_utils._initialize
+    else:
+        _addon_utils.reset_all(reload_scripts)
+    del _initialize
 
     # run the active integration preset
     filepath = preset_find(_user_preferences.inputs.active_keyconfig,




More information about the Bf-blender-cvs mailing list