Optimize tree structure with hash map for static children

This commit is contained in:
2025-10-26 12:59:45 +01:00
parent 152460aed6
commit db42316b49
3 changed files with 32 additions and 29 deletions

View File

@@ -7,7 +7,7 @@ This document compares Sux with other popular Go HTTP routers across various dim
Based on benchmark tests and the original README data:
### Static Routes (ns/op)
- **Sux**: 877.6 ns/op
- **Sux**: 798.5 ns/op (optimized with hash map)
- **httprouter**: ~900 ns/op (estimated from README)
- **gorilla/mux**: ~2000+ ns/op
- **chi**: ~1200 ns/op
@@ -20,6 +20,8 @@ Based on benchmark tests and the original README data:
- **chi**: Moderate allocations
- **gin**: Higher allocations due to more features
**Sux Performance Advantage**: Hash map optimization provides O(1) child lookups vs O(n) linear search
## Feature Comparison
| Feature | Sux | httprouter | gorilla/mux | chi | gin |
@@ -39,9 +41,10 @@ Based on benchmark tests and the original README data:
### Sux Advantages:
1. **Minimal Allocations**: Uses sync.Pool for parameter maps, reducing GC pressure
2. **Efficient Trie Structure**: Optimized for fast static route matching
3. **Lightweight Middleware**: Minimal overhead for middleware chains
4. **Zero Dependencies**: No external dependencies, smaller binary size
2. **Hash Map Optimization**: O(1) child lookups vs O(n) linear search in other routers
3. **Efficient Trie Structure**: Optimized for fast static route matching
4. **Lightweight Middleware**: Minimal overhead for middleware chains
5. **Zero Dependencies**: No external dependencies, smaller binary size
### Where Others Excel:
1. **gorilla/mux**: More flexible regex patterns