Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make KeyBytes allocates less memory (#418)
If the segments is less than the layouts, the we don't need to allocate full KeyFormat.length, just allocate enough memory to store the segments. name old time/op new time/op delta KeyFormat_KeyBytesOneSegment-8 19.2ns ± 0% 16.4ns ± 1% -14.62% (p=0.000 n=9+10) KeyFormat_KeyBytesThreeSegment-8 25.6ns ± 0% 25.9ns ± 1% +1.37% (p=0.000 n=10+10) KeyFormat_KeyBytesOneSegmentWithVariousLayouts-8 22.2ns ± 1% 16.4ns ± 0% -26.14% (p=0.000 n=10+8) KeyFormat_KeyBytesThreeSegmentWithVariousLayouts-8 28.8ns ± 3% 28.7ns ± 0% ~ (p=0.588 n=10+9) name old alloc/op new alloc/op delta KeyFormat_KeyBytesOneSegment-8 32.0B ± 0% 16.0B ± 0% -50.00% (p=0.000 n=10+10) KeyFormat_KeyBytesThreeSegment-8 32.0B ± 0% 32.0B ± 0% ~ (all equal) KeyFormat_KeyBytesOneSegmentWithVariousLayouts-8 64.0B ± 0% 16.0B ± 0% -75.00% (p=0.000 n=10+10) KeyFormat_KeyBytesThreeSegmentWithVariousLayouts-8 64.0B ± 0% 64.0B ± 0% ~ (all equal) name old allocs/op new allocs/op delta KeyFormat_KeyBytesOneSegment-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) KeyFormat_KeyBytesThreeSegment-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) KeyFormat_KeyBytesOneSegmentWithVariousLayouts-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) KeyFormat_KeyBytesThreeSegmentWithVariousLayouts-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) Fixes #417
- Loading branch information