fix: cut redirect and allow-path routing overhead

Reuse fixed-path and Allow-header buffers so redirect and OPTIONS handling stop rebuilding temporary data on every request. Cache fallback chains and add regression coverage for redirect, 404, 405, and Allow behavior to keep the faster miss paths stable.
This commit is contained in:
wjqserver 2026-04-07 09:06:56 +08:00
parent 5d979e5670
commit 2d4aefc86e
6 changed files with 264 additions and 48 deletions

View file

@ -16,6 +16,9 @@ func buildServeHTTPBenchmarkEngine() *Engine {
engine.GET("/api/v1/users/:id", func(c *Context) {
c.Status(http.StatusNoContent)
})
engine.GET("/api/v1/users/:id/settings", func(c *Context) {
c.Status(http.StatusNoContent)
})
engine.POST("/api/v1/users", func(c *Context) {
c.Status(http.StatusNoContent)
})
@ -61,4 +64,8 @@ func BenchmarkServeHTTP(b *testing.B) {
b.Run("OptionsAllow", func(b *testing.B) {
benchmarkServeHTTP(b, engine, http.MethodOptions, "/api/v1/users")
})
b.Run("FixedPathRedirect", func(b *testing.B) {
benchmarkServeHTTP(b, engine, http.MethodGet, "/API/V1/USERS/123/SETTINGS")
})
}