Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go api: reduce allocations in deck decompression
Previously we would allocate quite often in order to decompress and parse the deck strings that were given to us. This could be alleviated by precomputing some of the regular expressions, preallocating, and using manual conversion logic instead of relying on json. This could obviously be taken much further, but this seemed like a good compromise on benefit while still retaining readability. Benchmark comparison: ``` goos: linux goarch: amd64 pkg: github.com/MaT1g3R/slaytherelics/api cpu: AMD Ryzen 9 5900X 12-Core Processor │ before.txt │ after.txt │ │ sec/op │ sec/op vs base │ DecompressDeck/Simple_deck-24 7.934µ ± 1% 1.318µ ± 0% -83.39% (p=0.000 n=10) DecompressDeck/Big_deck-24 227.58µ ± 1% 60.34µ ± 1% -73.48% (p=0.000 n=10) geomean 42.49µ 8.916µ -79.02% │ before.txt │ after.txt │ │ B/op │ B/op vs base │ DecompressDeck/Simple_deck-24 5494.5 ± 0% 836.0 ± 0% -84.78% (p=0.000 n=10) DecompressDeck/Big_deck-24 330.8Ki ± 0% 219.2Ki ± 0% -33.72% (p=0.000 n=10) geomean 42.13Ki 13.38Ki -68.24% │ before.txt │ after.txt │ │ allocs/op │ allocs/op vs base │ DecompressDeck/Simple_deck-24 94.00 ± 0% 17.00 ± 0% -81.91% (p=0.000 n=10) DecompressDeck/Big_deck-24 1810.0 ± 0% 165.0 ± 0% -90.88% (p=0.000 n=10) geomean 412.5 52.96 -87.16% ```
- Loading branch information