ywxzm03 opened a new pull request, #3412:
URL: https://github.com/apache/dubbo-go/pull/3412
**What this PR does**:
Following the approach from #3404, this PR updates the remaining URL
key-building helpers in `common/url.go` from `fmt.Sprintf` / `bytes.Buffer` to
`strings.Builder` with preallocated capacity, reducing allocations and
formatting overhead:
- `Key()`: replaces `fmt.Sprintf` while preserving the output format
`protocol://username:password@ip:port/?interface=...&group=...&version=...`.
- `GetCacheInvokerMapKey()`: replaces `fmt.Sprintf` while preserving the
`timestamp` parameter (still using `primitiveTS`) and the `meshClusterID`
parameter.
- `ServiceKey()`: replaces `bytes.Buffer` with `strings.Builder` while
preserving edge-case behavior for empty `intf`, non-empty `group`, and
`version=0.0.0`.
**Which issue(s) this PR fixes**:
Fixes #3406
**Special notes for your reviewer**
- This benchmark reuses the existing URL benchmarks in
`common/url_benchmark_test.go`. The following comparison results were collected
on Apple M5 with `go test ./common -bench
'BenchmarkURL(Key|GetCacheInvokerMapKey|ServiceKey)' -benchmem`:
`BenchmarkURLKey`
| Case | Before | After
|
| ----------- | ---------------------------------- |
--------------------------------- |
| params_1 | 185.7 ns/op, 192 B/op, 7 allocs/op | 84.00 ns/op, 96 B/op, 1
allocs/op |
| params_32 | 193.3 ns/op, 192 B/op, 7 allocs/op | 64.81 ns/op, 96 B/op, 1
allocs/op |
| params_256 | 182.5 ns/op, 192 B/op, 7 allocs/op | 66.46 ns/op, 96 B/op, 1
allocs/op |
| params_1024 | 182.7 ns/op, 192 B/op, 7 allocs/op | 59.02 ns/op, 96 B/op, 1
allocs/op |
`BenchmarkURLGetCacheInvokerMapKey`
| Case | Before | After
|
| ----------- | ---------------------------------- |
---------------------------------- |
| params_1 | 233.0 ns/op, 272 B/op, 9 allocs/op | 76.95 ns/op, 144 B/op,
1 allocs/op |
| params_32 | 258.9 ns/op, 272 B/op, 9 allocs/op | 74.57 ns/op, 144 B/op,
1 allocs/op |
| params_256 | 237.1 ns/op, 272 B/op, 9 allocs/op | 88.17 ns/op, 144 B/op,
1 allocs/op |
| params_1024 | 237.3 ns/op, 272 B/op, 9 allocs/op | 74.62 ns/op, 144 B/op,
1 allocs/op |
`BenchmarkURLServiceKey`
| Case | Before | After
|
| ----------- | ---------------------------------- |
--------------------------------- |
| params_1 | 63.51 ns/op, 112 B/op, 2 allocs/op | 43.85 ns/op, 64 B/op, 2
allocs/op |
| params_32 | 54.99 ns/op, 112 B/op, 2 allocs/op | 48.87 ns/op, 64 B/op, 2
allocs/op |
| params_256 | 56.49 ns/op, 112 B/op, 2 allocs/op | 48.69 ns/op, 64 B/op, 2
allocs/op |
| params_1024 | 60.97 ns/op, 112 B/op, 2 allocs/op | 49.20 ns/op, 64 B/op, 2
allocs/op |
The benchmark comparison shows lower latency and memory usage across the
three URL key-building helpers.
- `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]