7 Commits

Author SHA1 Message Date
xfy
8e00e63972 chore: fix lint issues from performance optimization
- errcheck: check type assertions from sync.Pool.Get() in
  loadbalance/balancer.go and matcher/radix.go
- errcheck: check type assertion from list.Element.Value in
  resolver/resolver.go evictLRULocked
- revive: add doc comment for exported ReleaseMatchResult function
2026-06-04 00:22:45 +08:00
xfy
ba8c746a2e perf(matcher): eliminate heap allocations in RadixTree search with sync.Pool
RadixTree.searchLongest previously allocated &MatchResult{} on the
heap every time it encountered a handler-bearing node during tree
traversal — potentially N allocations per lookup with only 1 surviving.

Changes:
- searchLongest now tracks best *RadixNode (stack pointer) instead of
  allocating MatchResult at every handler node
- FindLongestPrefix allocates a single pooled MatchResult via sync.Pool
  only when returning a match
- Add ReleaseMatchResult() for callers to return MatchResult to pool
- LocationEngine.Match releases pooled results after use

Result: 0 B/op, 0 allocs/op on tree traversal benchmarks (sequential
and parallel).
2026-06-04 00:12:52 +08:00
xfy
65080cca66 feat(matcher): 支持 internal location 标记
- MatchResult 新增 Internal 字段
- AddExact/AddPrefix/AddPrefixPriority/AddRadix/AddRegex 方法新增 internal 参数
- location 解析器支持 internal 指令

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:08:23 +08:00
xfy
10f3da0954 docs(matcher): 为 location 匹配引擎添加标准化 godoc 注释
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:03 +08:00
xfy
6094327620 docs(matcher): 为 location 匹配引擎添加标准化 godoc 注释
为 matcher 包所有文件添加完整文档注释:
- conflict: 路径冲突检测器
- exact: 精确路径匹配器(O(1) hash map)
- location: 统一匹配引擎(整合所有策略)
- matcher: 匹配结果和接口定义
- named: 命名捕获组匹配器
- prefix: 普通前缀匹配器
- prefix_priority: 前缀优先匹配器(^~)
- radix: Radix Tree 最长前缀匹配
- regex: 正则表达式匹配器

注释说明匹配优先级顺序(精确 > 前缀优先 > 正则 > 普通前缀),
以及各匹配器的使用方法和性能特点。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 10:59:27 +08:00
xfy
ca03c121d3 refactor(matcher): 提取 LocationType 常量并优化结构体字段布局
- 添加 LocationType 常量定义替代硬编码字符串
- 优化 MatchResult、ExactMatcher、NamedMatcher 结构体字段顺序
- RadixTree.Insert 添加 locationType 参数用于调试追踪
- 更新测试代码适配新接口

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-17 10:11:45 +08:00
xfy
53eaec57ad feat(matcher): 添加 nginx 风格 location 匹配引擎
实现 nginx 兼容的 location 匹配系统,支持:
- 精确匹配 (=) - Hash Map O(1)
- 前缀优先匹配 (^~) - Radix Tree
- 正则匹配 (~, ~*) - 按配置顺序
- 普通前缀匹配 - Radix Tree 最长匹配
- 命名 location (@name) - 内部重定向

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-17 09:26:22 +08:00