refactor upstream routing lookup loop
Changes in this patch:
- use request method map to skip unnecessary lookups
- reuse u.URLPrefix.Strip in route lookup loop
- use reference in range to avoid allocation
Overall, we get 30% performance boost in routing speed and the memory usage is dropped more than 80% on average.
Some stats from go benchmark:
# all routes
Before:
BenchmarkRouteMatching-8 20000 66022 ns/op 1189 B/op 34 allocs/op
After:
BenchmarkRouteMatching-8 30000 47697 ns/op 254 B/op 8 allocs/op
# /assets/ route
Before:
BenchmarkRouteMatching-8 200000 7594 ns/op 113 B/op 5 allocs/op
After:
BenchmarkRouteMatching-8 300000 4905 ns/op 16 B/op 1 allocs/op