dubbo-go icon indicating copy to clipboard operation
dubbo-go copied to clipboard

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

Open Alanxtl opened this issue 5 months ago • 7 comments

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.

Alanxtl avatar Jun 09 '26 08:06 Alanxtl

Hello, may I try to do this?

ywxzm03 avatar Jun 09 '26 09:06 ywxzm03

@ywxzm03 pls do https://github.com/apache/dubbo-go/issues/3391 first to see the performance shift

Alanxtl avatar Jun 09 '26 09:06 Alanxtl

@ywxzm03 pls do #3391 first to see the performance shift

ok

ywxzm03 avatar Jun 09 '26 11:06 ywxzm03

Kindly ask if there somebody to working for this issue ? If not, I am glad to undertake it!

JunLa-0 avatar Jun 12 '26 00:06 JunLa-0

Kindly ask if there somebody to working for this issue ? If not, I am glad to undertake it!

@ywxzm03 what about you do #3393 and leave #3394 to @JunLa-0 ?

Alanxtl avatar Jun 12 '26 02:06 Alanxtl

#3393

ok

ywxzm03 avatar Jun 12 '26 05:06 ywxzm03

close via #3488

Alanxtl avatar Jul 19 '26 11:07 Alanxtl