perf(server): pass ctx.Path() directly to Match, eliminate string alloc

Removes the string(ctx.Path()) conversion that caused one heap
allocation per request in the routing hot path.
This commit is contained in:
xfy 2026-06-04 11:06:00 +08:00
parent aef0d8357b
commit 1eeab88c98

View File

@ -526,8 +526,7 @@ func (s *Server) startSingleMode() error {
// 创建主请求处理器,使用 LocationEngine 匹配路由
locationEngine := s.locationEngine
baseHandler := func(ctx *fasthttp.RequestCtx) {
path := string(ctx.Path())
result := locationEngine.Match(path)
result := locationEngine.Match(ctx.Path())
if result != nil && result.Handler != nil {
result.Handler(ctx)
return