Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up GLTF loading. #2275

Merged
merged 1 commit into from
Aug 27, 2024
Merged

Speed up GLTF loading. #2275

merged 1 commit into from
Aug 27, 2024

Conversation

eliphatfs
Copy link
Contributor

In my profile, more than 80% time is spent in the loop of strided accessor construction when loading GLTF/GLB files.

I thus applied np.lib.stride_tricks.as_strided to speed up the process.
I tested it on multiple glb files and the results are the same as the original logic.

This implementation also works for stride = 0, repeating the first element for count times. But glTF 2.0 specification 5.11.4 says it should be positive, so I added an assertion.

@mikedh
Copy link
Owner

mikedh commented Aug 27, 2024

Looks good!! The docs for as_strided do encourage "extreme caution" but it does look like you're checking all the things they warn about (copy the result, make sure data is long enough, etc). And you're right it's a nice speedup on corpus (although I'd also like to check that it loads the same number of meshes :)

This PR:
- 3.289 load_gltf  trimesh/exchange/gltf.py:268
- 3.054 load_glb  trimesh/exchange/gltf.py:343

Current `main`:
- 5.022 load_gltf  trimesh/exchange/gltf.py:268
- 3.616 load_glb  trimesh/exchange/gltf.py:343

@mikedh mikedh changed the base branch from main to feat/stride August 27, 2024 22:14
@mikedh mikedh merged commit 21bf209 into mikedh:feat/stride Aug 27, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants