From 51c0bc94efe34deb66b695447c2592870aecb638 Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Fri, 30 Jun 2023 17:34:48 +0100 Subject: [PATCH] FBX Import: Read known sequential bytes simultaneously The start of each element and the start of each array property have a consistent series of values with fixed sizes. Reading these series of values with a single read call and single unpack call is slightly faster than reading them individually. This reduces the time taken to parse fbx files to about 90% to 95% of the original time. Array decompression makes up about half of the time taken currently, but this could be multithreaded, in which case, this patch would reduce the time to about 80% to 90% instead. --- io_scene_fbx/parse_fbx.py | 43 +++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/io_scene_fbx/parse_fbx.py b/io_scene_fbx/parse_fbx.py index 154bbf494..19cd1f78c 100644 --- a/io_scene_fbx/parse_fbx.py +++ b/io_scene_fbx/parse_fbx.py @@ -20,7 +20,7 @@ from . import data_types # that the sub-scope exists (i.e. to distinguish between P: and P : {}) _BLOCK_SENTINEL_LENGTH = ... _BLOCK_SENTINEL_DATA = ... -read_fbx_elem_uint = ... +read_fbx_elem_start = ... _IS_BIG_ENDIAN = (__import__("sys").byteorder != 'little') _HEAD_MAGIC = b'Kaydara FBX Binary\x20\x20\x00\x1a\x00' from collections import namedtuple @@ -32,10 +32,6 @@ def read_uint(read): return unpack(b'