qmuntal / gltf

Go library for encoding glTF 2.0 files
https://www.khronos.org/gltf/
BSD 2-Clause "Simplified" License
243 stars 32 forks source link

Reduce modeler.Read helpers allocations #90

Closed qmuntal closed 2 months ago

qmuntal commented 2 months ago

Reduce reflection usage in binary.MakeSliceBuffer to improve performance.

goos: windows
goarch: amd64
pkg: github.com/qmuntal/gltf/modeler
cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz

                      │  old.txt   │               new.txt                │
                      │    B/op    │    B/op     vs base                  │
ReadAccessorSparse-12   296.0 ± 0%   248.0 ± 0%  -16.22% (p=0.000 n=10)
ReadAccessorBuffer-12   24.00 ± 0%   24.00 ± 0%        ~ (p=1.000 n=10) ¹
ReadAccessor-12         72.00 ± 0%   72.00 ± 0%        ~ (p=1.000 n=10) ¹
ReadIndices-12          56.00 ± 0%   32.00 ± 0%  -42.86% (p=0.000 n=10)
ReadIndicesBuffer-12    48.00 ± 0%   24.00 ± 0%  -50.00% (p=0.000 n=10)
geomean                 67.24        50.52       -24.87%
¹ all samples are equal

                      │  old.txt   │               new.txt                │
                      │ allocs/op  │ allocs/op   vs base                  │
ReadAccessorSparse-12   6.000 ± 0%   4.000 ± 0%  -33.33% (p=0.000 n=10)
ReadAccessorBuffer-12   1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=10) ¹
ReadAccessor-12         2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=10) ¹
ReadIndices-12          3.000 ± 0%   2.000 ± 0%  -33.33% (p=0.000 n=10)
ReadIndicesBuffer-12    2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)
geomean                 2.352        1.741       -25.98%
¹ all samples are equal