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

perf(common): optimize URL.String() locking and string building

Open Alanxtl opened this issue 5 months ago • 3 comments

Background

URL.String() is used in logging, registry, protocol, and comparison paths. It currently does read-only work but still takes the params write lock, and it builds the URL prefix through formatting before appending encoded params. This path can be made cheaper and less blocking while preserving current output.

Related to #3248.

Scope

Optimize common.URL.String():

  • Use paramsLock.RLock() instead of the write lock because the method only reads params.
  • Build the URL prefix with strings.Builder / Grow / WriteString instead of formatting into an intermediate string.
  • Preserve existing string output exactly, including behavior when there are no query params.
  • Keep params.Encode() behavior unless a benchmark-backed alternative is introduced with equivalent ordering semantics.

Acceptance criteria

  • Existing common tests continue to pass.
  • Add or update URL string benchmarks so the PR can show allocation/throughput impact with -benchmem.
  • No behavior change to URL formatting.

Alanxtl avatar Jun 09 '26 08:06 Alanxtl

Hello, may I try to do this?

ywxzm03 avatar Jun 09 '26 09: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

close via #3404

Alanxtl avatar Jun 13 '26 06:06 Alanxtl