Spireblight / STR-Backend

Slay the relics extension
https://dashboard.twitch.tv/extensions/ebkycs9lir8pbic2r0b7wa6bg6n7ua-0.0.1
GNU Affero General Public License v3.0
5 stars 2 forks source link

go api: remove regex replace when decompressing #20

Open zdylag opened 10 hours ago

zdylag commented 10 hours ago

Even without getting fancy with it, we can make this operation much faster and cheaper (for all real sized decks) by just using the built in tool for multireplacements in strings.

For clarity: in real life most decks will be more like the big deck case, since fewer runs spend much time at 3 distinct cards.

goos: linux
goarch: amd64
pkg: github.com/MaT1g3R/slaytherelics/api
cpu: AMD Ryzen 9 5900X 12-Core Processor
                              │   before    │                after                │
                              │   sec/op    │   sec/op     vs base                │
DecompressDeck/Simple_deck-24   1.310µ ± 1%   1.632µ ± 2%  +24.63% (p=0.000 n=10)
DecompressDeck/Big_deck-24      59.66µ ± 2%   17.57µ ± 0%  -70.56% (p=0.000 n=10)
geomean                         8.839µ        5.354µ       -39.42%

                              │    before     │                after                 │
                              │     B/op      │     B/op      vs base                │
DecompressDeck/Simple_deck-24      836.0 ± 0%    1560.0 ± 0%  +86.60% (p=0.000 n=10)
DecompressDeck/Big_deck-24      219.31Ki ± 0%   20.58Ki ± 0%  -90.62% (p=0.000 n=10)
geomean                          13.38Ki        5.599Ki       -58.16%

                              │   before    │               after                │
                              │  allocs/op  │ allocs/op   vs base                │
DecompressDeck/Simple_deck-24    17.00 ± 0%   21.00 ± 0%  +23.53% (p=0.000 n=10)
DecompressDeck/Big_deck-24      165.00 ± 0%   71.00 ± 0%  -56.97% (p=0.000 n=10)
geomean                          52.96        38.61       -27.09%
zdylag commented 10 hours ago

@MaT1g3R something that is not clear to me: Are nested compression strings allowed? EG: love|the|slay &1||I &0 &0 &2 relics and &2 spire -> I love love slay the relics and slay the spire? If so this approach (as is) does not work, and we should add ^ as a test case.

zdylag commented 9 hours ago

I made a PR to add the test cases just in case: https://github.com/Spireblight/STR-Backend/pull/21