complete lazy loading of py modules to use to a reduced set of pythons modules, gives ~40% speedup on cold & warm start (without netrender).
- use own OrderedDictMini class, pythons collections.OrderedDict is overkill, 179 sloc. replaced with own, 11 lines. - remove code which stored the class file & line per RNA subclass, this was useful but would raise its own exception every time to generate a stack trace to get the class info so we could use of the class failed to register. the class stores its module & name which can be enough to find where it was defined.
This commit is contained in:
@@ -103,9 +103,11 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
|
||||
:arg refresh_scripts: only load scripts which are not already loaded as modules.
|
||||
:type refresh_scripts: bool
|
||||
"""
|
||||
import time
|
||||
use_time = _bpy.app.debug
|
||||
|
||||
t_main = time.time()
|
||||
if use_time:
|
||||
import time
|
||||
t_main = time.time()
|
||||
|
||||
loaded_modules = set()
|
||||
|
||||
@@ -213,7 +215,7 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
|
||||
import gc
|
||||
print("gc.collect() -> %d" % gc.collect())
|
||||
|
||||
if _bpy.app.debug:
|
||||
if use_time:
|
||||
print("Python Script Load Time %.4f" % (time.time() - t_main))
|
||||
|
||||
|
||||
@@ -418,27 +420,27 @@ def _bpy_module_classes(module, is_registered=False):
|
||||
typemap_list = _bpy_types.TypeMap.get(module, ())
|
||||
i = 0
|
||||
while i < len(typemap_list):
|
||||
cls_weakref, path, line = typemap_list[i]
|
||||
cls_weakref = typemap_list[i]
|
||||
cls = cls_weakref()
|
||||
|
||||
if cls is None:
|
||||
del typemap_list[i]
|
||||
else:
|
||||
if is_registered == cls.is_registered:
|
||||
yield (cls, path, line)
|
||||
yield cls
|
||||
i += 1
|
||||
|
||||
|
||||
def register_module(module, verbose=False):
|
||||
if verbose:
|
||||
print("bpy.utils.register_module(%r): ..." % module)
|
||||
for cls, path, line in _bpy_module_classes(module, is_registered=False):
|
||||
for cls in _bpy_module_classes(module, is_registered=False):
|
||||
if verbose:
|
||||
print(" %s of %s:%s" % (cls, path, line))
|
||||
print(" %r" % cls)
|
||||
try:
|
||||
register_class(cls)
|
||||
except:
|
||||
print("bpy.utils.register_module(): failed to registering class '%s.%s'" % (cls.__module__, cls.__name__))
|
||||
print("bpy.utils.register_module(): failed to registering class %r" % cls)
|
||||
print("\t", path, "line", line)
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
@@ -451,13 +453,13 @@ def register_module(module, verbose=False):
|
||||
def unregister_module(module, verbose=False):
|
||||
if verbose:
|
||||
print("bpy.utils.unregister_module(%r): ..." % module)
|
||||
for cls, path, line in _bpy_module_classes(module, is_registered=True):
|
||||
for cls in _bpy_module_classes(module, is_registered=True):
|
||||
if verbose:
|
||||
print(" %s of %s:%s" % (cls, path, line))
|
||||
print(" %r" % cls)
|
||||
try:
|
||||
unregister_class(cls)
|
||||
except:
|
||||
print("bpy.utils.unregister_module(): failed to unregistering class '%s.%s'" % (cls.__module__, cls.__name__))
|
||||
print("bpy.utils.unregister_module(): failed to unregistering class %r" % cls)
|
||||
print("\t", path, "line", line)
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
Reference in New Issue
Block a user