FBX Import: Speed up parsing by reading entire subtrees into BytesIO #104822
No reviewers
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#104822
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Mysteryem/blender-addons:fbx_subtrees_bytesio_pr"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Python's default BufferedReader used with open() has to get the raw
stream position from the OS on every tell() call. This is about 10 times
slower than the tell() function of BytesIO objects. Because the number
of bytes in each FBX element's subtree is known ahead of time, entire
subtrees of bytes can be read at once and exposed through IO API as
BytesIO for a performance increase.
The "Objects" element's subtree is an exception and is not read all at
once because it usually makes up the vast majority of the file size.
Reading what could be a huge number of bytes into memory at once could
impact performance on systems with low free memory, especially because
those bytes won't be freed until they have been entirely parsed.
A small amount of refactoring has also been done to reduce the number of
required tell() calls.
This reduces the time taken to parse fbx files to about 88% to 90% of
the original time in most cases. 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 75% to 80% instead.
Imported files containing lots of very small or non-nested subtrees
within the "Objects" element's subtree won't see much, if any effect
from this patch, which can happen with bone animations with many
animated bones.
besides minor typo in comment noted below, LGTM, thanks!
And as usual, thanks for the detailed explanations in PR and comments!
@ -132,0 +132,4 @@
if pos < local_end_offset:
# The default BufferedReader used when `open()`-ing files in 'rb' mode has to get the raw stream position from
# the OS every time its tell() function is called. This is about 10 times slower than the tell() function of
# BytesIO objects, so reading chunks of bytes from the file into memory as once and exposing them through
Typo:
...into memory _at_ once...
;)08476de4a4
to5e45e449cd
The typo in the comment has been corrected.