From e09189cf50682016e69fb207b010447c3bc6471d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 28 Feb 2011 04:37:24 +0000 Subject: 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. --- release/scripts/modules/bpy_types.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'release/scripts/modules/bpy_types.py') diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index f7429474b06..f3daee49474 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -567,18 +567,15 @@ TypeMap = {} class RNAMeta(type): def __new__(cls, name, bases, classdict, **args): result = type.__new__(cls, name, bases, classdict) - if bases and bases[0] != StructRNA: - import traceback - import weakref + if bases and bases[0] is not StructRNA: + from _weakref import ref as ref module = result.__module__ # first part of packages only if "." in module: module = module[:module.index(".")] - sf = traceback.extract_stack(limit=2)[0] - - TypeMap.setdefault(module, []).append((weakref.ref(result), sf[0], sf[1])) + TypeMap.setdefault(module, []).append(ref(result)) return result @@ -586,7 +583,20 @@ class RNAMeta(type): def is_registered(cls): return "bl_rna" in cls.__dict__ -import collections + +class OrderedDictMini(dict): + def __init__(self, *args): + self.order = [] + dict.__init__(self, args) + + def __setitem__(self, key, val): + dict.__setitem__(self, key, val) + if key not in self.order: + self.order.append(key) + + def __delitem__(self, key): + dict.__delitem__(self, key) + self.order.remove(key) class RNAMetaPropGroup(RNAMeta, StructMetaPropGroup): @@ -600,7 +610,7 @@ class OrderedMeta(RNAMeta): cls.order = list(attributes.keys()) def __prepare__(name, bases, **kwargs): - return collections.OrderedDict() + return OrderedDictMini() # collections.OrderedDict() # Only defined so operators members can be used by accessing self.order -- cgit v1.2.3