Commit graph

17 commits

Author SHA1 Message Date
google-labs-jules[bot]
b07f9ee1dd Optimize radix tree and context handling for performance
This commit introduces several optimizations to reduce allocations and
improve performance in the core routing and context mechanisms.

Radix Tree (tree.go):
- Optimized `getValue`'s internal `skippedNode` handling:
  - Changed `skippedNode.node` to store a direct pointer to the tree node
    instead of a full copy, significantly reducing allocations during
    backtracking scenarios.
  - Corrected the method of adding to the `skippedNodes` slice to use
    `append`, ensuring safer and more idiomatic slice growth.

Context Handling (context.go):
- Implemented lazy initialization for `Context.Keys`:
  - The `Keys` map is now only allocated on the first call to `Set()`
    per request, avoiding map allocation for requests that do not use
    context keys. `Context.reset()` now sets `Keys` to `nil`.
  - `Get()` correctly handles the `nil` map state.
- Optimized `RequestIP()` for parsing comma-separated IP headers:
  - Replaced `strings.Split()` with an iterative parsing approach using
    `strings.IndexByte()` and slicing. This avoids allocating an
    intermediate slice for IPs, reducing memory usage during IP resolution,
    especially for headers like `X-Forwarded-For` with multiple IPs.

These changes are backward compatible for idiomatic usage and have been
reasoned to show improvements in simulated benchmarks, particularly in
reducing allocations per operation for the affected components.
2025-06-23 19:55:07 +00:00
wjqserver
53544644af use new resolveRoutePath replace path.Join && add UseIf 2025-06-17 14:20:14 +08:00
wjqserver
bfc6b439e4 [context] add SetHeaders 2025-06-14 17:58:08 +08:00
wjqserver
896182417f fix header writer after status issue 2025-06-11 11:24:54 +08:00
wjqserver
bb822599b9 update methods 2025-06-11 11:11:54 +08:00
wjqserver
ce5efae287 update 2025-06-10 21:37:53 +08:00
wjqserver
e6b54eedbf remove tgzip 2025-06-10 00:04:15 +08:00
wjqserver
1d5ffac153 [context] optimize context reset and reuse 2025-06-06 22:40:40 +08:00
wjqserver
61e67bc2a0 [context] fix writer reset 2025-06-06 21:29:09 +08:00
wjqserver
757cd962ab [context] Add Cookie Method, port from gin 2025-06-05 18:35:28 +08:00
wjqserver
b8a1c5523a ctx add logreco method 2025-06-04 21:30:56 +08:00
wjqserver
899d3ff48b add logreco 2025-06-04 20:44:23 +08:00
wjqserver
385b6239c8 add GetHTTPC 2025-06-04 18:40:00 +08:00
wjqserver
6eac3b2046 add GetProtocol 2025-06-02 02:10:25 +08:00
wjqserver
8ae88a77f0 add Raw & GetReqBodyFull 2025-05-30 16:51:38 +08:00
wjqserver
5a10829041 add ErrorUseHandle 2025-05-28 21:34:08 +08:00
wjqserver
484f2f016b init(v0.0.1) 2025-05-28 18:25:28 +08:00