Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eliminate memory allocations from Compress/Decompress.
Go allocates a copy of slice headers when they are passed to C functions. See golang/go#24450 for details. Avoid this by passing unsafe.Pointer as C.uintptr_t into C functions. Benchmark results: $ PAYLOAD=ZSTD_LICENSE go test -run=111 -bench='k[CD]' -benchmem -count=10 name old time/op new time/op delta Compression-4 21.2µs ± 5% 20.8µs ± 6% ~ (p=0.190 n=10+10) Decompression-4 7.37µs ± 5% 6.93µs ± 6% -5.95% (p=0.001 n=10+10) name old speed new speed delta Compression-4 62.5MB/s ± 5% 63.7MB/s ± 6% ~ (p=0.190 n=10+10) Decompression-4 180MB/s ± 5% 191MB/s ± 6% +6.35% (p=0.001 n=10+10) name old alloc/op new alloc/op delta Compression-4 96.0B ± 0% 0.0B -100.00% (p=0.000 n=10+10) Decompression-4 96.0B ± 0% 0.0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Compression-4 4.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) Decompression-4 4.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10)
- Loading branch information