From f2f824ad85243ecdd3b9610d6c5a59846238e0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 8 Mar 2018 13:59:28 +0100 Subject: [PATCH] Speed up BlendFileBlock instantiation with __slots__ Due to the huge number of BlendFileBlock objects created for packing a production-size blend file, using slots here actually makes the dependency tracer significantly (p<0.001) faster. In my test case the speed improvement was 16% for a 'bam list' command. --- blender_asset_tracer/blendfile/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/blender_asset_tracer/blendfile/__init__.py b/blender_asset_tracer/blendfile/__init__.py index bbd7962..9b31bd3 100644 --- a/blender_asset_tracer/blendfile/__init__.py +++ b/blender_asset_tracer/blendfile/__init__.py @@ -38,7 +38,6 @@ from blender_asset_tracer import bpathlib log = logging.getLogger(__name__) FILE_BUFFER_SIZE = 1024 * 1024 - BLENDFILE_MAGIC = b'BLENDER' GZIP_MAGIC = b'\x1f\x8b' @@ -378,6 +377,16 @@ class BlendFileBlock: """ Instance of a struct. """ + + # Due to the huge number of BlendFileBlock objects created for packing a + # production-size blend file, using slots here actually makes the + # dependency tracer significantly (p<0.001) faster. In my test case the + # speed improvement was 16% for a 'bam list' command. + __slots__ = ( + 'bfile', 'code', 'size', 'addr_old', 'sdna_index', + 'count', 'file_offset', 'endian', '_id_name', + ) + log = log.getChild('BlendFileBlock') old_structure = struct.Struct(b'4sI') """old blend files ENDB block structure"""