This document tracks performance optimizations and future improvement opportunities.
- Impact: 80-89% faster reflection operations
- Implementation: Global
sync.Mapcache for method info - Benefit: Zero allocations for unbound method lookups
- Impact: 10-17% faster URL generation
- Implementation: Per-context cache with RWMutex
- Benefit: Eliminated redundant pattern parsing
- Impact: 3% faster request handling with params
- Implementation: Store parsed segments in PageNode at Mount time
- Benefit: Zero parsing overhead in extractURLParams middleware
Run benchmarks to verify performance:
# Full benchmark suite
go test -bench=. -benchmem
# Specific categories
go test -bench=BenchmarkRequestHandling -benchmem
go test -bench=BenchmarkURLGeneration -benchmem
go test -bench=BenchmarkIDGeneration -benchmem
go test -bench=BenchmarkReflection -benchmem-
Pool availableArgs Maps
- Use
sync.Poolfor argument maps in method calling - Estimated improvement: 5-10% in request handling
- Use
-
Optimize kebabToPascal
- Single-pass implementation without
strings.Split - Estimated improvement: 50% in HTMX target matching
- Single-pass implementation without
-
Cache Component Results
- For pure components with no side effects
- Requires careful API design
-
Reduce Context Value() Calls
- Extract once at handler start
- Pass as struct instead of multiple lookups
Current performance (Apple M3 Ultra):
- Simple GET request: ~760ns
- Request with URL params: ~1050ns
- URL generation (1 param): ~226ns
- ID generation (unbound): ~167ns
- extractMethodInfo (cached): ~8ns
Memory per request:
- Simple GET: 1466B, 16 allocs
- With params: 2188B, 20 allocs