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

Wildcard lookup optimization #36

Merged
merged 5 commits into from
Jul 15, 2024
Merged

Wildcard lookup optimization #36

merged 5 commits into from
Jul 15, 2024

Conversation

tigerwill90
Copy link
Owner

@tigerwill90 tigerwill90 commented Jul 15, 2024

This PR improves wildcard route performance by ~10%. Instead of parsing parameters during the lookup phase, parameters are now parsed during the tree-building phase and can be directly retrieved during lookup. Previously, parsing time increased with the size of the wildcard key due to searching for the next '/', which was expensive for very long keys. This issue has been resolved.

Benchmark Differential

goos: linux
goarch: amd64
pkg: github.com/tigerwill90/fox
cpu: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
                    │    old.txt    │               new.txt               │
                    │    sec/op     │   sec/op     vs base                │
StaticAll-16           11.17µ ±  2%   10.91µ ± 1%   -2.32% (p=0.000 n=10)
GithubParamsAll-16     84.64n ±  1%   75.31n ± 2%  -11.03% (p=0.000 n=10)
OverlappingRoute-16   100.60n ±  1%   87.16n ± 2%  -13.35% (p=0.000 n=10)
StaticParallel-16      9.518n ±  3%   9.234n ± 3%   -2.98% (p=0.002 n=10)
CatchAll-16            31.97n ±  2%   31.67n ± 4%        ~ (p=0.280 n=10)
CatchAllParallel-16    5.820n ± 16%   5.904n ± 7%        ~ (p=1.000 n=10)
CloneWith-16           67.27n ±  2%   66.33n ± 2%        ~ (p=0.078 n=10)
geomean                73.27n         69.96n        -4.51%

And comparing with Gin and Echo for wildcard route:

BenchmarkFox_GithubAll-16          70188             16357 ns/op               0 B/op          0 allocs/op
BenchmarkEcho_GithubAll-16         56134             20734 ns/op               0 B/op          0 allocs/op
BenchmarkGin_GithubAll-16          70112             17793 ns/op               0 B/op          0 allocs/op

Copy link

codecov bot commented Jul 15, 2024

Codecov Report

Attention: Patch coverage is 71.87500% with 18 lines in your changes missing coverage. Please review.

Project coverage is 87.95%. Comparing base (8fcce12) to head (fadb0ff).
Report is 1 commits behind head on master.

Files Patch % Lines
node.go 75.00% 12 Missing and 1 partial ⚠️
tree.go 63.63% 4 Missing ⚠️
context.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #36      +/-   ##
==========================================
+ Coverage   87.15%   87.95%   +0.79%     
==========================================
  Files          15       15              
  Lines        1939     1992      +53     
==========================================
+ Hits         1690     1752      +62     
+ Misses        193      183      -10     
- Partials       56       57       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tigerwill90 tigerwill90 marked this pull request as ready for review July 15, 2024 16:37
pawndev
pawndev previously approved these changes Jul 15, 2024
node.go Show resolved Hide resolved
@tigerwill90 tigerwill90 merged commit e546791 into master Jul 15, 2024
7 of 8 checks passed
@tigerwill90 tigerwill90 deleted the feat/improved-routing branch July 15, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants