jkuhlmann / cgltf

:diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99
MIT License
1.42k stars 135 forks source link

Optimize data extraction from accessors #219

Closed zeux closed 1 year ago

zeux commented 1 year ago

This is mostly focused on cgltf_accessor_unpack_floats, but also adds a counterpart cgltf_accessor_unpack_indices.

The optimizations reduce the overhead by extracting some common code out of the per-element loop, and also implementing a fast path for direct memcpy. Without the fast path, this results in ~10% faster glTF parsing (tested end-to-end on Amazon Bistro exterior scene); with the fast-path, this makes the parsing 1.5x faster. Note that the time includes loading gltf/buffer data from files, parsing/validation and some minor data reorganization, so the gains may be more significant in other applications - the numbers above are from gltfpack.