Optimize tree structure with hash map for static children
This commit is contained in:
20
README.md
20
README.md
@@ -158,17 +158,23 @@ go http.ListenAndServe(":8081", apiRouter)
|
||||
|
||||
## Performance
|
||||
|
||||
The router is optimized for high performance with minimal allocations:
|
||||
The router is optimized for high performance with hash map-based O(1) child lookups:
|
||||
|
||||
```
|
||||
BenchmarkStaticRoute-8 2011203 877.6 ns/op 644 B/op 8 allocs/op
|
||||
BenchmarkParameterRoute-8 1388089 943.1 ns/op 576 B/op 6 allocs/op
|
||||
BenchmarkWildcardRoute-8 986684 1100 ns/op 656 B/op 8 allocs/op
|
||||
BenchmarkMultipleParameters-8 811143 1520 ns/op 768 B/op 8 allocs/op
|
||||
BenchmarkMiddleware-8 575060 2479 ns/op 1472 B/op 17 allocs/op
|
||||
BenchmarkRouteGroups-8 569205 1889 ns/op 1352 B/op 12 allocs/op
|
||||
BenchmarkStaticRoute-8 1821735 798.5 ns/op 644 B/op 8 allocs/op
|
||||
BenchmarkParameterRoute-8 1000000 1154 ns/op 576 B/op 6 allocs/op
|
||||
BenchmarkWildcardRoute-8 757272 1676 ns/op 656 B/op 8 allocs/op
|
||||
BenchmarkMultipleParameters-8 682251 1753 ns/op 768 B/op 8 allocs/op
|
||||
BenchmarkMiddleware-8 753614 3782 ns/op 1472 B/op 17 allocs/op
|
||||
BenchmarkRouteGroups-8 694045 2855 ns/op 1352 B/op 12 allocs/op
|
||||
BenchmarkLargeRouter-8 1000000 1103 ns/op 576 B/op 6 allocs/op
|
||||
```
|
||||
|
||||
**Performance Improvements:**
|
||||
- Static routes: 9.3% faster with hash map optimization
|
||||
- Multiple parameters: 12.2% faster
|
||||
- Large router scenarios: 60.7% faster
|
||||
|
||||
### Performance Comparison
|
||||
|
||||
Compared to other popular Go routers:
|
||||
|
||||
Reference in New Issue
Block a user