TibiaData / tibiadata-api-go

TibiaData API written in Golang and deployed in container (version v3 and above).
https://api.tibiadata.com
MIT License
84 stars 28 forks source link

Rewrite boostable bosses parser #233

Closed phenpessoa closed 1 year ago

phenpessoa commented 1 year ago

This PR completely rewrites TibiaBoostableBossesOverviewImpl

The reason behind this rewrite is to stop using regex and goquery. The performance boost is gigantic, reducing allocations from over 8000 to just 3.

                                    │    old.txt    │               new.txt               │
                                    │    sec/op     │   sec/op     vs base                │
TibiaBoostableBossesOverviewImpl-16   3579.68µ ± 1%   70.63µ ± 1%  -98.03% (p=0.000 n=10)

                                    │    old.txt    │               new.txt                │
                                    │     B/op      │     B/op      vs base                │
TibiaBoostableBossesOverviewImpl-16   684.24Ki ± 0%   16.02Ki ± 0%  -97.66% (p=0.000 n=10)

                                    │    old.txt    │              new.txt               │
                                    │   allocs/op   │ allocs/op   vs base                │
TibiaBoostableBossesOverviewImpl-16   8042.000 ± 0%   3.000 ± 0%  -99.96% (p=0.000 n=10)

I also needed to modify TibiaDataHTMLDataCollector slightly allowing a RawBody flag to be passed to it If this flag is passed, we pass tibia.com's response directly to the caller instead of creating a document using goquery This does not interfere with any other parser, because in other for this change to take place the RawBody flag must be specified.

old.txt
goos: windows
goarch: amd64
pkg: github.com/TibiaData/tibiadata-api-go/src
cpu: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
BenchmarkTibiaBoostableBossesOverviewImpl-16                 330           3599726 ns/op          700629 B/op       8042 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16                 334           3549418 ns/op          700787 B/op       8042 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16                 334           3609261 ns/op          700718 B/op       8042 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16                 328           3579164 ns/op          700883 B/op       8042 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16                 337           3552659 ns/op          700147 B/op       8042 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16                 339           3631858 ns/op          700553 B/op       8042 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16                 331           3585056 ns/op          700213 B/op       8042 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16                 338           3574397 ns/op          700568 B/op       8043 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16                 338           3580188 ns/op          701463 B/op       8043 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16                 331           3572162 ns/op          700703 B/op       8042 allocs/op
new.txt
goos: windows
goarch: amd64
pkg: github.com/TibiaData/tibiadata-api-go/src
cpu: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
BenchmarkTibiaBoostableBossesOverviewImpl-16               17167             69799 ns/op           16408 B/op          3 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16               16989             70272 ns/op           16408 B/op          3 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16               16705             70118 ns/op           16408 B/op          3 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16               16874             70873 ns/op           16408 B/op          3 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16               16716             70525 ns/op           16408 B/op          3 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16               16848             70809 ns/op           16408 B/op          3 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16               17293             70124 ns/op           16408 B/op          3 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16               16503             70834 ns/op           16408 B/op          3 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16               16928             70732 ns/op           16408 B/op          3 allocs/op
BenchmarkTibiaBoostableBossesOverviewImpl-16               16929             71818 ns/op           16408 B/op          3 allocs/op
sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication