dubbo-go
dubbo-go copied to clipboard
perf(common): optimize URL.String() locking and string building
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/WriteStringinstead 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
commontests 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.
Hello, may I try to do this?
Kindly ask if there somebody to working for this issue ? If not, I am glad to undertake it!
close via #3404