ywxzm03 opened a new pull request, #3404:
URL: https://github.com/apache/dubbo-go/pull/3404

   **What this PR does**:
   
   Optimizes lock usage and string construction in `common.URL.String()`, 
making it lighter-weight and less blocking while keeping the existing output 
exactly unchanged.
   
   This change includes:
   
   - **Locking**: changes `paramsLock.Lock()` to `paramsLock.RLock()`, because 
this method only reads params. A read lock allows multiple concurrent 
`String()` calls while still remaining mutually exclusive with writes.
   - **String construction**: replaces `fmt.Sprintf` with `strings.Builder` + 
`Grow` + `WriteString`. By precomputing the required capacity and allocating 
once, this removes intermediate strings and repeated growth.
   
   **Which issue(s) this PR fixes**:
   
   Fixes #3393
   
   **Special notes for your reviewer**:
   
   - The benchmark reuses the existing `BenchmarkURLString` on develop 
(`common/url_benchmark_test.go`, from #3399). Comparison results from `go test 
./common/ -bench BenchmarkURLString -benchmem` on Apple M5:
   
     | Case        | Before                                | After              
                       |
     | ----------- | ------------------------------------- | 
----------------------------------------- |
     | params_1    | 383.2 ns/op, 728 B/op, 13 allocs/op   | 309.7 ns/op, 536 
B/op, **7 allocs/op**    |
     | params_32   | 1651 ns/op, 3385 B/op, 16 allocs/op   | 1804 ns/op, 3192 
B/op, **10 allocs/op**   |
     | params_256  | 18138 ns/op, 21698 B/op, 20 allocs/op | 18499 ns/op, 21496 
B/op, **14 allocs/op** |
     | params_1024 | 95501 ns/op, 98025 B/op, 25 allocs/op | 91318 ns/op, 97784 
B/op, **19 allocs/op** |
   
     Latency drops noticeably for small URLs. For large params cases, runtime 
is mostly dominated by `params.Encode()`, so latency is roughly unchanged, but 
the allocation count still decreases.
   
   - `go test ./common/` passes.
   
   **Does this PR introduce a user-facing change?**
   
   ```release-note
   NONE


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to