Skip to content

perf(common): avoid unnecessary allocations in URL IsEquals and ToMap #3394

Description

@Alanxtl

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.

Metadata

Metadata

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions