perf(core): 极限性能优化,路由匹配提升 ~50%,生产网络配置调优#198
Merged
hubertshelley merged 3 commits intomainfrom Mar 25, 2026
Merged
Conversation
- handler_trait: 消除 HashMap clone,改为直接引用 + Arc::clone - route_connection: RouteTree 启动时一次性构建,所有连接共享 Arc<RouteTree> - route_tree: 无中间件快速路径跳过 Next 链构建;not_found 零分配 - next: 中间件链调用避免不必要的 Arc clone - quic/service: 同步适配 Arc<RouteTree> 共享机制 - Cargo.toml: release profile 添加 LTO/codegen-units=1/strip - 新增 no-tracing feature,benchmark 场景编译时关闭 tracing Benchmark 结果(vs main): 简单路由: 107ns → 53ns (~50%) 中间件路由: 108ns → 49ns (~55%) 嵌套路由: 132ns → 91ns (~31%) 1000 请求: 185µs → 131µs (~29%)
from_parts 原先通过 ..Self::default() 展开,内部会构造一个完整的 http::Request 再拆解为 Parts,而这个 Parts 随即被调用者传入的值覆盖。 现改为直接内联构造所有字段,避免无意义的中间分配。
- listener: TCP accept 后立即设置 set_nodelay(true),
禁用 Nagle 算法减少跨网络小包延迟
- route_connection: 配置 hyper Builder 参数
- HTTP/1.1: 启用 pipeline_flush 减少响应延迟
- HTTP/2: 流窗口 1MB、连接窗口 2MB、自适应窗口、
最大并发流 256,提升高延迟网络吞吐
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
self.clone().get()→self.get()+Arc::clone,消除每请求的 HashMap 深拷贝Arc<RouteTree>,所有 HTTP/QUIC 连接共享,消除每连接重建SilentError::NotFound替代BusinessError+ String 分配..Self::default()导致的多余http::Request构造+拆解Benchmark 结果(Criterion 路由匹配层,vs main)
端到端 HTTP benchmark(bombardier, localhost):~14万 RPS,与 main 持平。
路由匹配层优化在端到端场景中被 I/O 和 runtime 开销稀释(路由匹配仅占总延迟 ~6%)。
TCP_NODELAY 和 hyper 调优在真实跨网络场景中生效。
Test plan