Background
IsEquals() currently converts both URLs to maps via ToMap(), deletes excluded keys, and then compares the maps. This creates avoidable allocations for a comparison-only path. ToMap() itself can also be tightened by pre-sizing the map and avoiding repeated string splits.
Related to #3248.
Scope
Optimize equality and map conversion paths:
- Rework
IsEquals() to compare fields and params directly without materializing two full maps when possible.
- Treat excluded params through a small lookup set instead of deleting from copied maps.
- Keep
ToMap() public behavior unchanged, but reduce allocation work where possible.
- Avoid repeated parsing of
Location; use a single-pass split strategy while preserving current host/port behavior.
Acceptance criteria
- Existing equality and
ToMap() tests continue to pass.
- Add or update benchmarks for
IsEquals() and ToMap() with small and larger param sets.
- The PR shows
-benchmem output demonstrating lower allocations or no regression.
go test ./common passes.
Background
IsEquals()currently converts both URLs to maps viaToMap(), deletes excluded keys, and then compares the maps. This creates avoidable allocations for a comparison-only path.ToMap()itself can also be tightened by pre-sizing the map and avoiding repeated string splits.Related to #3248.
Scope
Optimize equality and map conversion paths:
IsEquals()to compare fields and params directly without materializing two full maps when possible.ToMap()public behavior unchanged, but reduce allocation work where possible.Location; use a single-pass split strategy while preserving current host/port behavior.Acceptance criteria
ToMap()tests continue to pass.IsEquals()andToMap()with small and larger param sets.-benchmemoutput demonstrating lower allocations or no regression.go test ./commonpasses.