Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite boostable bosses parser #233

Merged

Conversation

phenpessoa
Copy link
Contributor

@phenpessoa phenpessoa commented Jun 30, 2023

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

@phenpessoa phenpessoa mentioned this pull request Jun 30, 2023
57 tasks
@tobiasehlert tobiasehlert force-pushed the rewrite-boostable-bosses-parser branch from ab8d7fa to d4761a1 Compare July 3, 2023 21:07
@sonarcloud
Copy link

sonarcloud bot commented Jul 3, 2023

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

@tobiasehlert tobiasehlert self-requested a review July 3, 2023 21:21
@tobiasehlert tobiasehlert added the go Pull requests that update Go code label Jul 3, 2023
@tobiasehlert tobiasehlert merged commit 37eeae4 into TibiaData:main Jul 3, 2023
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code
Development

Successfully merging this pull request may close these issues.

None yet

2 participants