You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "ywxzm03 (via GitHub)" <gi...@apache.org> on 2026/06/11 07:55:58 UTC
[PR] Feat: add benchmarks for common.URL [dubbo-go]
ywxzm03 opened a new pull request, #3399:
URL: https://github.com/apache/dubbo-go/pull/3399
<!-- Thanks for sending a pull request! -->
**What this PR does**:
Add focused benchmarks for `common.URL` to establish a quantifiable baseline (throughput + memory allocation) for future optimization, so changes can be evaluated with data rather than intuition.
This PR only adds `common/url_benchmark_test.go` and does not change any production code.
Methods covered:
- `URL.String()`
- `URL.Key()`
- `URL.GetCacheInvokerMapKey()`
- `URL.ServiceKey()`
- `URL.Clone()` / `URL.CloneWithFilter()`
- `URL.MergeURL()`
- `URL.CopyParams()` / `URL.GetParams()`
- `URL.IsEquals()` / `URL.ToMap()`
Test dimensions:
- Parameter sizes use four tiers: `1 / 32 / 256 / 1024`.
- `Clone` / `CloneWithFilter` include cases with `SubURL` to surface deep-copy costs.
- All methods with return values write their results to package-level sink variables to prevent the compiler from optimizing the calls away and skewing the data.
**Which issue(s) this PR fixes**:
Fixes #3391
**Special notes for your reviewer**:
Benchmark command:
```bash
go test ./common -bench 'BenchmarkURL' -benchmem -run '^$'
```
Output:
```text
goos: darwin
goarch: arm64
pkg: dubbo.apache.org/dubbo-go/v3/common
cpu: Apple M5
BenchmarkURLString/params_1-10 5456774 200.9 ns/op 384 B/op 9 allocs/op
BenchmarkURLString/params_32-10 843082 1515 ns/op 2297 B/op 15 allocs/op
BenchmarkURLString/params_256-10 67254 17780 ns/op 21698 B/op 20 allocs/op
BenchmarkURLString/params_1024-10 10000 109537 ns/op 98024 B/op 25 allocs/op
BenchmarkURLKey/params_1-10 7146849 166.9 ns/op 144 B/op 5 allocs/op
BenchmarkURLKey/params_32-10 6561790 181.4 ns/op 192 B/op 7 allocs/op
BenchmarkURLKey/params_256-10 6466377 182.3 ns/op 192 B/op 7 allocs/op
BenchmarkURLKey/params_1024-10 5680776 211.8 ns/op 192 B/op 7 allocs/op
BenchmarkURLGetCacheInvokerMapKey/params_1-10 5943622 196.2 ns/op 176 B/op 5 allocs/op
BenchmarkURLGetCacheInvokerMapKey/params_32-10 5188357 236.4 ns/op 272 B/op 9 allocs/op
BenchmarkURLGetCacheInvokerMapKey/params_256-10 4854295 235.6 ns/op 272 B/op 9 allocs/op
BenchmarkURLGetCacheInvokerMapKey/params_1024-10 5031062 238.2 ns/op 272 B/op 9 allocs/op
BenchmarkURLServiceKey/params_1-10 26704621 43.71 ns/op 96 B/op 2 allocs/op
BenchmarkURLServiceKey/params_32-10 21432190 56.21 ns/op 112 B/op 2 allocs/op
BenchmarkURLServiceKey/params_256-10 21643898 54.96 ns/op 112 B/op 2 allocs/op
BenchmarkURLServiceKey/params_1024-10 21134046 56.68 ns/op 112 B/op 2 allocs/op
BenchmarkURLCopyParams/params_1-10 11519364 103.3 ns/op 416 B/op 3 allocs/op
BenchmarkURLCopyParams/params_32-10 1290672 951.0 ns/op 3288 B/op 36 allocs/op
BenchmarkURLCopyParams/params_256-10 166741 7114 ns/op 25944 B/op 260 allocs/op
BenchmarkURLCopyParams/params_1024-10 39529 30732 ns/op 114816 B/op 1030 allocs/op
BenchmarkURLGetParams/params_1-10 11502212 104.6 ns/op 416 B/op 3 allocs/op
BenchmarkURLGetParams/params_32-10 1274205 950.0 ns/op 3288 B/op 36 allocs/op
BenchmarkURLGetParams/params_256-10 167067 7076 ns/op 25944 B/op 260 allocs/op
BenchmarkURLGetParams/params_1024-10 39504 30974 ns/op 114816 B/op 1030 allocs/op
BenchmarkURLClone/params_1-10 6889875 174.7 ns/op 752 B/op 6 allocs/op
BenchmarkURLClone/params_32-10 580028 2054 ns/op 6152 B/op 44 allocs/op
BenchmarkURLClone/params_256-10 75308 15982 ns/op 47848 B/op 274 allocs/op
BenchmarkURLClone/params_1024-10 18219 66097 ns/op 207704 B/op 1049 allocs/op
BenchmarkURLClone/params_1_with_suburl-10 3433593 351.6 ns/op 1504 B/op 12 allocs/op
BenchmarkURLClone/params_32_with_suburl-10 285583 5181 ns/op 12304 B/op 88 allocs/op
BenchmarkURLClone/params_256_with_suburl-10 31632 32658 ns/op 95696 B/op 548 allocs/op
BenchmarkURLClone/params_1024_with_suburl-10 8587 142742 ns/op 415408 B/op 2098 allocs/op
BenchmarkURLCloneWithFilter/params_1-10 6699319 176.1 ns/op 752 B/op 6 allocs/op
BenchmarkURLCloneWithFilter/params_32-10 575073 2080 ns/op 6152 B/op 44 allocs/op
BenchmarkURLCloneWithFilter/params_256-10 75116 16063 ns/op 47848 B/op 274 allocs/op
BenchmarkURLCloneWithFilter/params_1024-10 17505 65511 ns/op 207704 B/op 1049 allocs/op
BenchmarkURLCloneWithFilter/params_1_exclude_20_percent-10 9886900 121.3 ns/op 384 B/op 4 allocs/op
BenchmarkURLCloneWithFilter/params_32_exclude_20_percent-10 713469 1613 ns/op 3336 B/op 36 allocs/op
BenchmarkURLCloneWithFilter/params_256_exclude_20_percent-10 89206 13946 ns/op 25240 B/op 221 allocs/op
BenchmarkURLCloneWithFilter/params_1024_exclude_20_percent-10 21150 55510 ns/op 106056 B/op 840 allocs/op
BenchmarkURLCloneWithFilter/params_1_reserve_20_percent-10 6833206 174.9 ns/op 752 B/op 6 allocs/op
BenchmarkURLCloneWithFilter/params_32_reserve_20_percent-10 2262472 526.4 ns/op 832 B/op 11 allocs/op
BenchmarkURLCloneWithFilter/params_256_reserve_20_percent-10 104593 11450 ns/op 6456 B/op 63 allocs/op
BenchmarkURLCloneWithFilter/params_1024_reserve_20_percent-10 6982 172265 ns/op 25224 B/op 220 allocs/op
BenchmarkURLMergeURL/params_1_with_method_params-10 407398 2933 ns/op 6152 B/op 90 allocs/op
BenchmarkURLMergeURL/params_32_with_method_params-10 147805 8156 ns/op 19600 B/op 200 allocs/op
BenchmarkURLMergeURL/params_256_with_method_params-10 29161 41295 ns/op 102992 B/op 988 allocs/op
BenchmarkURLMergeURL/params_1024_with_method_params-10 6880 175043 ns/op 446737 B/op 3687 allocs/op
BenchmarkURLToMap/params_1-10 7867472 171.8 ns/op 400 B/op 4 allocs/op
BenchmarkURLToMap/params_32-10 638270 1844 ns/op 4536 B/op 11 allocs/op
BenchmarkURLToMap/params_256-10 86206 13509 ns/op 37400 B/op 17 allocs/op
BenchmarkURLToMap/params_1024-10 21568 56515 ns/op 160392 B/op 24 allocs/op
BenchmarkURLIsEquals/params_1-10 2960374 398.3 ns/op 800 B/op 8 allocs/op
BenchmarkURLIsEquals/params_32-10 298500 7196 ns/op 9072 B/op 22 allocs/op
BenchmarkURLIsEquals/params_256-10 34377 32492 ns/op 74800 B/op 34 allocs/op
BenchmarkURLIsEquals/params_1024-10 9354 127971 ns/op 320784 B/op 48 allocs/op
PASS
ok dubbo.apache.org/dubbo-go/v3/common 84.654s
```
**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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl merged PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#issuecomment-4687058113
记得以后target branch都弄成develop 这次我直接给你改了吧
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on code in PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#discussion_r3395052831
##########
common/url_benchmark_test.go:
##########
@@ -0,0 +1,304 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package common
+
+import (
+ "fmt"
+ "net/url"
+ "testing"
+)
+
+import (
+ gxset "github.com/dubbogo/gost/container/set"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+)
+
+const (
+ benchmarkURLProtocol = "dubbo"
+ benchmarkURLIP = "127.0.0.1"
+ benchmarkURLPort = "20000"
+ benchmarkURLInterface = "com.test.BenchmarkService"
+ benchmarkURLGroup = "benchmark"
+ benchmarkURLVersion = "1.0.0"
+ benchmarkURLTimestamp = "1234567890"
+ benchmarkURLMeshID = "benchmark-mesh"
+)
+
+var (
+ benchmarkURLParamSizes = []int{1, 32, 256, 1024}
+
+ benchmarkURLStringSink string
+ benchmarkURLSink *URL
+ benchmarkURLParamsSink url.Values
+ benchmarkURLMapSink map[string]string
+ benchmarkURLBoolSink bool
+)
+
+func BenchmarkURLString(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.String()
+ })
+}
+
+func BenchmarkURLKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.Key()
+ })
+}
+
+func BenchmarkURLGetCacheInvokerMapKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.GetCacheInvokerMapKey()
+ })
+}
+
+func BenchmarkURLServiceKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.ServiceKey()
+ })
+}
+
+func BenchmarkURLCopyParams(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLParamsSink = u.CopyParams()
+ })
+}
+
+func BenchmarkURLGetParams(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLParamsSink = u.GetParams()
+ })
+}
+
+func BenchmarkURLClone(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLSink = u.Clone()
+ })
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_with_suburl", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURLWithSubURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.Clone()
+ }
+ })
+ }
+}
+
+func BenchmarkURLCloneWithFilter(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLSink = u.CloneWithFilter(nil, nil)
+ })
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_exclude_20_percent", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ excludeParams := makeBenchmarkExcludeSet(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.CloneWithFilter(excludeParams, nil)
+ }
+ })
+ }
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_reserve_20_percent", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ reserveParams := makeBenchmarkReserveKeys(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.CloneWithFilter(nil, reserveParams)
+ }
+ })
+ }
+}
+
+func BenchmarkURLMergeURL(b *testing.B) {
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_with_method_params", paramCount), func(b *testing.B) {
+ left, right := makeBenchmarkMergeHalfOverlapPair(paramCount)
+ addBenchmarkMethodParams(right)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = left.MergeURL(right)
+ }
+ })
+ }
+}
+
+func BenchmarkURLToMap(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLMapSink = u.ToMap()
+ })
+}
+
+func BenchmarkURLIsEquals(b *testing.B) {
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d", paramCount), func(b *testing.B) {
+ left := makeBenchmarkURL(paramCount)
+ right := makeBenchmarkURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLBoolSink = IsEquals(left, right)
+ }
+ })
+ }
+}
+
+func runBenchmarkURLByParamSize(b *testing.B, run func(*URL)) {
+ b.Helper()
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ run(u)
+ }
+ })
+ }
+}
+
+func makeBenchmarkURL(paramCount int) *URL {
+ return makeBenchmarkURLWithParamStart(paramCount, 0)
+}
+
+func makeBenchmarkURLWithSubURL(paramCount int) *URL {
+ u := makeBenchmarkURL(paramCount)
+ u.SubURL = makeBenchmarkURL(paramCount)
+ return u
+}
+
+func makeBenchmarkURLWithParamStart(paramCount int, genericStart int) *URL {
+ u := NewURLWithOptions(
+ WithProtocol(benchmarkURLProtocol),
+ WithIp(benchmarkURLIP),
+ WithPort(benchmarkURLPort),
+ WithPath(benchmarkURLInterface),
+ WithMethods(makeBenchmarkMethods()),
+ WithParams(makeBenchmarkParams(paramCount, genericStart)),
+ )
+ u.primitiveTS = u.GetParam(constant.TimestampKey, "")
+ return u
+}
+
+func makeBenchmarkMergeHalfOverlapPair(paramCount int) (*URL, *URL) {
+ genericCount := paramCount - len(benchmarkURLIdentityParams)
+ if genericCount < 0 {
+ genericCount = 0
+ }
+ return makeBenchmarkURL(paramCount), makeBenchmarkURLWithParamStart(paramCount, genericCount/2)
+}
+
+func makeBenchmarkParams(paramCount int, genericStart int) url.Values {
+ params := make(url.Values, paramCount)
+ for i, param := range benchmarkURLIdentityParams {
+ if i >= paramCount {
+ return params
+ }
+ params.Set(param.key, param.value)
+ }
+ for i := len(benchmarkURLIdentityParams); i < paramCount; i++ {
+ genericIndex := genericStart + i - len(benchmarkURLIdentityParams)
+ params.Set(fmt.Sprintf("key%d", genericIndex), fmt.Sprintf("value%d", genericIndex))
+ }
+ return params
+}
Review Comment:
fixed
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#issuecomment-4678415755
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3399) **Quality Gate passed**
Issues
 [2 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3399&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3399&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3399&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3399&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3399&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3399)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#discussion_r3395723782
##########
common/url_benchmark_test.go:
##########
@@ -0,0 +1,294 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package common
+
+import (
+ "fmt"
+ "net/url"
+ "testing"
+)
+
+import (
+ gxset "github.com/dubbogo/gost/container/set"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+)
+
+const (
+ benchmarkURLProtocol = "dubbo"
+ benchmarkURLIP = "127.0.0.1"
+ benchmarkURLPort = "20000"
+ benchmarkURLInterface = "com.test.BenchmarkService"
+ benchmarkURLGroup = "benchmark"
+ benchmarkURLVersion = "1.0.0"
+ benchmarkURLTimestamp = "1234567890"
+ benchmarkURLMeshID = "benchmark-mesh"
+)
+
+var (
+ benchmarkURLParamSizes = []int{1, 32, 256, 1024}
+
+ benchmarkURLStringSink string
+ benchmarkURLSink *URL
+ benchmarkURLParamsSink url.Values
+ benchmarkURLMapSink map[string]string
+ benchmarkURLBoolSink bool
+)
+
+func BenchmarkURLString(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.String()
+ })
+}
+
+func BenchmarkURLKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.Key()
+ })
+}
+
+func BenchmarkURLGetCacheInvokerMapKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.GetCacheInvokerMapKey()
+ })
+}
+
+func BenchmarkURLServiceKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.ServiceKey()
+ })
+}
+
+func BenchmarkURLCopyParams(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLParamsSink = u.CopyParams()
+ })
+}
+
+func BenchmarkURLGetParams(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLParamsSink = u.GetParams()
+ })
+}
+
+func BenchmarkURLClone(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLSink = u.Clone()
+ })
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_with_suburl", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURLWithSubURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.Clone()
+ }
+ })
+ }
+}
+
+func BenchmarkURLCloneWithFilter(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLSink = u.CloneWithFilter(nil, nil)
+ })
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_exclude_20_percent", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ excludeParams := makeBenchmarkExcludeSet(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.CloneWithFilter(excludeParams, nil)
+ }
+ })
+ }
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_reserve_20_percent", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ reserveParams := makeBenchmarkReserveKeys(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.CloneWithFilter(nil, reserveParams)
+ }
+ })
+ }
+}
Review Comment:
`BenchmarkURLCloneWithFilter` doesn't include any `SubURL` cases, but the PR description mentions using `SubURL` to surface deep-copy costs for `CloneWithFilter`. Consider adding a `with_suburl` sub-benchmark here (similar to `BenchmarkURLClone`) so the suite matches the documented dimensions and covers the `SubURL` cloning path.
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#issuecomment-4687661332
> 记得以后target branch都弄成develop 这次我直接给你改了吧
好的好的
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#issuecomment-4691109732
上面那个基准测试结果是main的,搞错了,这是develop的:
```
goos: darwin
goarch: arm64
pkg: dubbo.apache.org/dubbo-go/v3/common
cpu: Apple M5
BenchmarkURLString/params_1-10 3026236 383.2 ns/op 728 B/op 13 allocs/op
BenchmarkURLString/params_32-10 698642 1651 ns/op 3385 B/op 16 allocs/op
BenchmarkURLString/params_256-10 66152 18138 ns/op 21698 B/op 20 allocs/op
BenchmarkURLString/params_1024-10 13412 95501 ns/op 98025 B/op 25 allocs/op
BenchmarkURLKey/params_1-10 6306699 185.7 ns/op 192 B/op 7 allocs/op
BenchmarkURLKey/params_32-10 6529956 193.3 ns/op 192 B/op 7 allocs/op
BenchmarkURLKey/params_256-10 6662924 182.5 ns/op 192 B/op 7 allocs/op
BenchmarkURLKey/params_1024-10 6467244 182.7 ns/op 192 B/op 7 allocs/op
BenchmarkURLGetCacheInvokerMapKey/params_1-10 5027041 233.0 ns/op 272 B/op 9 allocs/op
BenchmarkURLGetCacheInvokerMapKey/params_32-10 5069215 258.9 ns/op 272 B/op 9 allocs/op
BenchmarkURLGetCacheInvokerMapKey/params_256-10 5124664 237.1 ns/op 272 B/op 9 allocs/op
BenchmarkURLGetCacheInvokerMapKey/params_1024-10 5019613 237.3 ns/op 272 B/op 9 allocs/op
BenchmarkURLServiceKey/params_1-10 21817784 63.51 ns/op 112 B/op 2 allocs/op
BenchmarkURLServiceKey/params_32-10 21063440 54.99 ns/op 112 B/op 2 allocs/op
BenchmarkURLServiceKey/params_256-10 21789426 56.49 ns/op 112 B/op 2 allocs/op
BenchmarkURLServiceKey/params_1024-10 21540874 60.97 ns/op 112 B/op 2 allocs/op
BenchmarkURLCopyParams/params_1-10 6203845 206.8 ns/op 496 B/op 8 allocs/op
BenchmarkURLCopyParams/params_32-10 1000000 1107 ns/op 3368 B/op 41 allocs/op
BenchmarkURLCopyParams/params_256-10 163902 7490 ns/op 26024 B/op 265 allocs/op
BenchmarkURLCopyParams/params_1024-10 34876 31195 ns/op 114896 B/op 1035 allocs/op
BenchmarkURLGetParams/params_1-10 6623463 180.1 ns/op 496 B/op 8 allocs/op
BenchmarkURLGetParams/params_32-10 1000000 1058 ns/op 3368 B/op 41 allocs/op
BenchmarkURLGetParams/params_256-10 168154 7291 ns/op 26024 B/op 265 allocs/op
BenchmarkURLGetParams/params_1024-10 39310 30801 ns/op 114896 B/op 1035 allocs/op
BenchmarkURLClone/params_1-10 4174020 282.7 ns/op 832 B/op 11 allocs/op
BenchmarkURLClone/params_32-10 544749 2177 ns/op 6232 B/op 49 allocs/op
BenchmarkURLClone/params_256-10 73340 16474 ns/op 47928 B/op 279 allocs/op
BenchmarkURLClone/params_1024-10 18205 65924 ns/op 207784 B/op 1054 allocs/op
BenchmarkURLClone/params_1_with_suburl-10 2078948 571.2 ns/op 1664 B/op 22 allocs/op
BenchmarkURLClone/params_32_with_suburl-10 269206 4404 ns/op 12464 B/op 98 allocs/op
BenchmarkURLClone/params_256_with_suburl-10 36600 32677 ns/op 95856 B/op 558 allocs/op
BenchmarkURLClone/params_1024_with_suburl-10 8144 156119 ns/op 415568 B/op 2108 allocs/op
BenchmarkURLCloneWithFilter/params_1-10 4061169 315.3 ns/op 832 B/op 11 allocs/op
BenchmarkURLCloneWithFilter/params_32-10 540829 2186 ns/op 6232 B/op 49 allocs/op
BenchmarkURLCloneWithFilter/params_256-10 74157 16173 ns/op 47928 B/op 279 allocs/op
BenchmarkURLCloneWithFilter/params_1024-10 18078 65462 ns/op 207784 B/op 1054 allocs/op
BenchmarkURLCloneWithFilter/params_1_exclude_20_percent-10 3939213 312.7 ns/op 816 B/op 10 allocs/op
BenchmarkURLCloneWithFilter/params_32_exclude_20_percent-10 437833 2467 ns/op 6120 B/op 42 allocs/op
BenchmarkURLCloneWithFilter/params_256_exclude_20_percent-10 84950 14719 ns/op 25304 B/op 225 allocs/op
BenchmarkURLCloneWithFilter/params_1024_exclude_20_percent-10 20248 58591 ns/op 106120 B/op 844 allocs/op
BenchmarkURLCloneWithFilter/params_1_exclude_20_percent_with_suburl-10 1907947 606.4 ns/op 1648 B/op 21 allocs/op
BenchmarkURLCloneWithFilter/params_32_exclude_20_percent_with_suburl-10 264130 4534 ns/op 12352 B/op 91 allocs/op
BenchmarkURLCloneWithFilter/params_256_exclude_20_percent_with_suburl-10 38130 30610 ns/op 73232 B/op 504 allocs/op
BenchmarkURLCloneWithFilter/params_1024_exclude_20_percent_with_suburl-10 9326 130434 ns/op 313904 B/op 1898 allocs/op
BenchmarkURLCloneWithFilter/params_1_reserve_20_percent-10 6084813 220.9 ns/op 752 B/op 6 allocs/op
BenchmarkURLCloneWithFilter/params_32_reserve_20_percent-10 1917904 632.5 ns/op 848 B/op 12 allocs/op
BenchmarkURLCloneWithFilter/params_256_reserve_20_percent-10 100050 13070 ns/op 6472 B/op 64 allocs/op
BenchmarkURLCloneWithFilter/params_1024_reserve_20_percent-10 6087 183739 ns/op 25240 B/op 221 allocs/op
BenchmarkURLCloneWithFilter/params_1_reserve_20_percent_with_suburl-10 2495181 699.4 ns/op 1584 B/op 17 allocs/op
BenchmarkURLCloneWithFilter/params_32_reserve_20_percent_with_suburl-10 394444 3245 ns/op 7080 B/op 61 allocs/op
BenchmarkURLCloneWithFilter/params_256_reserve_20_percent_with_suburl-10 40737 34839 ns/op 54400 B/op 343 allocs/op
BenchmarkURLCloneWithFilter/params_1024_reserve_20_percent_with_suburl-10 4531 264162 ns/op 233024 B/op 1275 allocs/op
BenchmarkURLMergeURL/params_1_with_method_params-10 336252 3462 ns/op 6360 B/op 103 allocs/op
BenchmarkURLMergeURL/params_32_with_method_params-10 118677 10057 ns/op 19888 B/op 218 allocs/op
BenchmarkURLMergeURL/params_256_with_method_params-10 24115 46353 ns/op 103280 B/op 1006 allocs/op
BenchmarkURLMergeURL/params_1024_with_method_params-10 6734 180407 ns/op 447025 B/op 3705 allocs/op
BenchmarkURLToMap/params_1-10 3374077 479.2 ns/op 1016 B/op 7 allocs/op
BenchmarkURLToMap/params_32-10 677581 2499 ns/op 4536 B/op 11 allocs/op
BenchmarkURLToMap/params_256-10 68665 19297 ns/op 37400 B/op 17 allocs/op
BenchmarkURLToMap/params_1024-10 18144 66803 ns/op 160392 B/op 24 allocs/op
BenchmarkURLIsEquals/params_1-10 993952 1174 ns/op 2032 B/op 14 allocs/op
BenchmarkURLIsEquals/params_32-10 222820 5310 ns/op 9072 B/op 22 allocs/op
BenchmarkURLIsEquals/params_256-10 31465 37645 ns/op 74800 B/op 34 allocs/op
BenchmarkURLIsEquals/params_1024-10 7587 155206 ns/op 320784 B/op 48 allocs/op
PASS
ok dubbo.apache.org/dubbo-go/v3/common 95.390s
```
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#issuecomment-4681151480
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3399) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3399&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3399&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3399&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3399&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3399&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3399)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#discussion_r3394567949
##########
common/url_benchmark_test.go:
##########
@@ -0,0 +1,304 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package common
+
+import (
+ "fmt"
+ "net/url"
+ "testing"
+)
+
+import (
+ gxset "github.com/dubbogo/gost/container/set"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+)
+
+const (
+ benchmarkURLProtocol = "dubbo"
+ benchmarkURLIP = "127.0.0.1"
+ benchmarkURLPort = "20000"
+ benchmarkURLInterface = "com.test.BenchmarkService"
+ benchmarkURLGroup = "benchmark"
+ benchmarkURLVersion = "1.0.0"
+ benchmarkURLTimestamp = "1234567890"
+ benchmarkURLMeshID = "benchmark-mesh"
+)
+
+var (
+ benchmarkURLParamSizes = []int{1, 32, 256, 1024}
+
+ benchmarkURLStringSink string
+ benchmarkURLSink *URL
+ benchmarkURLParamsSink url.Values
+ benchmarkURLMapSink map[string]string
+ benchmarkURLBoolSink bool
+)
+
+func BenchmarkURLString(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.String()
+ })
+}
+
+func BenchmarkURLKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.Key()
+ })
+}
+
+func BenchmarkURLGetCacheInvokerMapKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.GetCacheInvokerMapKey()
+ })
+}
+
+func BenchmarkURLServiceKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.ServiceKey()
+ })
+}
+
+func BenchmarkURLCopyParams(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLParamsSink = u.CopyParams()
+ })
+}
+
+func BenchmarkURLGetParams(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLParamsSink = u.GetParams()
+ })
+}
+
+func BenchmarkURLClone(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLSink = u.Clone()
+ })
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_with_suburl", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURLWithSubURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.Clone()
+ }
+ })
+ }
+}
+
+func BenchmarkURLCloneWithFilter(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLSink = u.CloneWithFilter(nil, nil)
+ })
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_exclude_20_percent", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ excludeParams := makeBenchmarkExcludeSet(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.CloneWithFilter(excludeParams, nil)
+ }
+ })
+ }
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_reserve_20_percent", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ reserveParams := makeBenchmarkReserveKeys(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.CloneWithFilter(nil, reserveParams)
+ }
+ })
+ }
+}
+
+func BenchmarkURLMergeURL(b *testing.B) {
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_with_method_params", paramCount), func(b *testing.B) {
+ left, right := makeBenchmarkMergeHalfOverlapPair(paramCount)
+ addBenchmarkMethodParams(right)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = left.MergeURL(right)
+ }
+ })
+ }
+}
+
+func BenchmarkURLToMap(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLMapSink = u.ToMap()
+ })
+}
+
+func BenchmarkURLIsEquals(b *testing.B) {
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d", paramCount), func(b *testing.B) {
+ left := makeBenchmarkURL(paramCount)
+ right := makeBenchmarkURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLBoolSink = IsEquals(left, right)
+ }
+ })
+ }
+}
+
+func runBenchmarkURLByParamSize(b *testing.B, run func(*URL)) {
+ b.Helper()
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ run(u)
+ }
+ })
+ }
+}
+
+func makeBenchmarkURL(paramCount int) *URL {
+ return makeBenchmarkURLWithParamStart(paramCount, 0)
+}
+
+func makeBenchmarkURLWithSubURL(paramCount int) *URL {
+ u := makeBenchmarkURL(paramCount)
+ u.SubURL = makeBenchmarkURL(paramCount)
+ return u
+}
+
+func makeBenchmarkURLWithParamStart(paramCount int, genericStart int) *URL {
+ u := NewURLWithOptions(
+ WithProtocol(benchmarkURLProtocol),
+ WithIp(benchmarkURLIP),
+ WithPort(benchmarkURLPort),
+ WithPath(benchmarkURLInterface),
+ WithMethods(makeBenchmarkMethods()),
+ WithParams(makeBenchmarkParams(paramCount, genericStart)),
+ )
+ u.primitiveTS = u.GetParam(constant.TimestampKey, "")
+ return u
+}
+
+func makeBenchmarkMergeHalfOverlapPair(paramCount int) (*URL, *URL) {
+ genericCount := paramCount - len(benchmarkURLIdentityParams)
+ if genericCount < 0 {
+ genericCount = 0
+ }
+ return makeBenchmarkURL(paramCount), makeBenchmarkURLWithParamStart(paramCount, genericCount/2)
+}
+
+func makeBenchmarkParams(paramCount int, genericStart int) url.Values {
Review Comment:
```suggestion
func makeBenchmarkParams(paramCount, genericStart int) url.Values {
```
##########
common/url_benchmark_test.go:
##########
@@ -0,0 +1,304 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package common
+
+import (
+ "fmt"
+ "net/url"
+ "testing"
+)
+
+import (
+ gxset "github.com/dubbogo/gost/container/set"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+)
+
+const (
+ benchmarkURLProtocol = "dubbo"
+ benchmarkURLIP = "127.0.0.1"
+ benchmarkURLPort = "20000"
+ benchmarkURLInterface = "com.test.BenchmarkService"
+ benchmarkURLGroup = "benchmark"
+ benchmarkURLVersion = "1.0.0"
+ benchmarkURLTimestamp = "1234567890"
+ benchmarkURLMeshID = "benchmark-mesh"
+)
+
+var (
+ benchmarkURLParamSizes = []int{1, 32, 256, 1024}
+
+ benchmarkURLStringSink string
+ benchmarkURLSink *URL
+ benchmarkURLParamsSink url.Values
+ benchmarkURLMapSink map[string]string
+ benchmarkURLBoolSink bool
+)
+
+func BenchmarkURLString(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.String()
+ })
+}
+
+func BenchmarkURLKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.Key()
+ })
+}
+
+func BenchmarkURLGetCacheInvokerMapKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.GetCacheInvokerMapKey()
+ })
+}
+
+func BenchmarkURLServiceKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.ServiceKey()
+ })
+}
+
+func BenchmarkURLCopyParams(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLParamsSink = u.CopyParams()
+ })
+}
+
+func BenchmarkURLGetParams(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLParamsSink = u.GetParams()
+ })
+}
+
+func BenchmarkURLClone(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLSink = u.Clone()
+ })
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_with_suburl", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURLWithSubURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.Clone()
+ }
+ })
+ }
+}
+
+func BenchmarkURLCloneWithFilter(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLSink = u.CloneWithFilter(nil, nil)
+ })
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_exclude_20_percent", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ excludeParams := makeBenchmarkExcludeSet(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.CloneWithFilter(excludeParams, nil)
+ }
+ })
+ }
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_reserve_20_percent", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ reserveParams := makeBenchmarkReserveKeys(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.CloneWithFilter(nil, reserveParams)
+ }
+ })
+ }
+}
+
+func BenchmarkURLMergeURL(b *testing.B) {
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_with_method_params", paramCount), func(b *testing.B) {
+ left, right := makeBenchmarkMergeHalfOverlapPair(paramCount)
+ addBenchmarkMethodParams(right)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = left.MergeURL(right)
+ }
+ })
+ }
+}
+
+func BenchmarkURLToMap(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLMapSink = u.ToMap()
+ })
+}
+
+func BenchmarkURLIsEquals(b *testing.B) {
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d", paramCount), func(b *testing.B) {
+ left := makeBenchmarkURL(paramCount)
+ right := makeBenchmarkURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLBoolSink = IsEquals(left, right)
+ }
+ })
+ }
+}
+
+func runBenchmarkURLByParamSize(b *testing.B, run func(*URL)) {
+ b.Helper()
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ run(u)
+ }
+ })
+ }
+}
+
+func makeBenchmarkURL(paramCount int) *URL {
+ return makeBenchmarkURLWithParamStart(paramCount, 0)
+}
+
+func makeBenchmarkURLWithSubURL(paramCount int) *URL {
+ u := makeBenchmarkURL(paramCount)
+ u.SubURL = makeBenchmarkURL(paramCount)
+ return u
+}
+
+func makeBenchmarkURLWithParamStart(paramCount int, genericStart int) *URL {
+ u := NewURLWithOptions(
+ WithProtocol(benchmarkURLProtocol),
+ WithIp(benchmarkURLIP),
+ WithPort(benchmarkURLPort),
+ WithPath(benchmarkURLInterface),
+ WithMethods(makeBenchmarkMethods()),
+ WithParams(makeBenchmarkParams(paramCount, genericStart)),
+ )
+ u.primitiveTS = u.GetParam(constant.TimestampKey, "")
+ return u
+}
+
+func makeBenchmarkMergeHalfOverlapPair(paramCount int) (*URL, *URL) {
+ genericCount := paramCount - len(benchmarkURLIdentityParams)
+ if genericCount < 0 {
+ genericCount = 0
+ }
+ return makeBenchmarkURL(paramCount), makeBenchmarkURLWithParamStart(paramCount, genericCount/2)
+}
+
+func makeBenchmarkParams(paramCount int, genericStart int) url.Values {
+ params := make(url.Values, paramCount)
+ for i, param := range benchmarkURLIdentityParams {
+ if i >= paramCount {
+ return params
+ }
+ params.Set(param.key, param.value)
+ }
+ for i := len(benchmarkURLIdentityParams); i < paramCount; i++ {
+ genericIndex := genericStart + i - len(benchmarkURLIdentityParams)
+ params.Set(fmt.Sprintf("key%d", genericIndex), fmt.Sprintf("value%d", genericIndex))
+ }
+ return params
+}
Review Comment:
benchmark 维度有点误导
`makeBenchmarkParams(paramCount, ...)` 把 `paramCount` 当成“总参数数”。所以 `params_1` 只包含 `interface`,但没有 `group/version/timestamp/meshClusterID`;而 `params_32+` 才包含完整 identity params。这样 `BenchmarkURLServiceKey`、`BenchmarkURLKey`、`BenchmarkURLGetCacheInvokerMapKey` 的 `params_1` 和其它 tier 测的不是同一种语义 URL,后续看趋势时容易误判“参数量影响”。建议始终保留 identity params,把 `1/32/256/1024` 定义成额外 generic 参数数,或者把 case 命名成 `total_params_N` 并单独加完整 identity 的小参数 case。
##########
common/url_benchmark_test.go:
##########
@@ -0,0 +1,304 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package common
+
+import (
+ "fmt"
+ "net/url"
+ "testing"
+)
+
+import (
+ gxset "github.com/dubbogo/gost/container/set"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+)
+
+const (
+ benchmarkURLProtocol = "dubbo"
+ benchmarkURLIP = "127.0.0.1"
+ benchmarkURLPort = "20000"
+ benchmarkURLInterface = "com.test.BenchmarkService"
+ benchmarkURLGroup = "benchmark"
+ benchmarkURLVersion = "1.0.0"
+ benchmarkURLTimestamp = "1234567890"
+ benchmarkURLMeshID = "benchmark-mesh"
+)
+
+var (
+ benchmarkURLParamSizes = []int{1, 32, 256, 1024}
+
+ benchmarkURLStringSink string
+ benchmarkURLSink *URL
+ benchmarkURLParamsSink url.Values
+ benchmarkURLMapSink map[string]string
+ benchmarkURLBoolSink bool
+)
+
+func BenchmarkURLString(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.String()
+ })
+}
+
+func BenchmarkURLKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.Key()
+ })
+}
+
+func BenchmarkURLGetCacheInvokerMapKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.GetCacheInvokerMapKey()
+ })
+}
+
+func BenchmarkURLServiceKey(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLStringSink = u.ServiceKey()
+ })
+}
+
+func BenchmarkURLCopyParams(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLParamsSink = u.CopyParams()
+ })
+}
+
+func BenchmarkURLGetParams(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLParamsSink = u.GetParams()
+ })
+}
+
+func BenchmarkURLClone(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLSink = u.Clone()
+ })
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_with_suburl", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURLWithSubURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.Clone()
+ }
+ })
+ }
+}
+
+func BenchmarkURLCloneWithFilter(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLSink = u.CloneWithFilter(nil, nil)
+ })
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_exclude_20_percent", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ excludeParams := makeBenchmarkExcludeSet(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.CloneWithFilter(excludeParams, nil)
+ }
+ })
+ }
+
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_reserve_20_percent", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ reserveParams := makeBenchmarkReserveKeys(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = u.CloneWithFilter(nil, reserveParams)
+ }
+ })
+ }
+}
+
+func BenchmarkURLMergeURL(b *testing.B) {
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d_with_method_params", paramCount), func(b *testing.B) {
+ left, right := makeBenchmarkMergeHalfOverlapPair(paramCount)
+ addBenchmarkMethodParams(right)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLSink = left.MergeURL(right)
+ }
+ })
+ }
+}
+
+func BenchmarkURLToMap(b *testing.B) {
+ runBenchmarkURLByParamSize(b, func(u *URL) {
+ benchmarkURLMapSink = u.ToMap()
+ })
+}
+
+func BenchmarkURLIsEquals(b *testing.B) {
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d", paramCount), func(b *testing.B) {
+ left := makeBenchmarkURL(paramCount)
+ right := makeBenchmarkURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ benchmarkURLBoolSink = IsEquals(left, right)
+ }
+ })
+ }
+}
+
+func runBenchmarkURLByParamSize(b *testing.B, run func(*URL)) {
+ b.Helper()
+ for _, paramCount := range benchmarkURLParamSizes {
+ paramCount := paramCount
+ b.Run(fmt.Sprintf("params_%d", paramCount), func(b *testing.B) {
+ u := makeBenchmarkURL(paramCount)
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ run(u)
+ }
+ })
+ }
+}
+
+func makeBenchmarkURL(paramCount int) *URL {
+ return makeBenchmarkURLWithParamStart(paramCount, 0)
+}
+
+func makeBenchmarkURLWithSubURL(paramCount int) *URL {
+ u := makeBenchmarkURL(paramCount)
+ u.SubURL = makeBenchmarkURL(paramCount)
+ return u
+}
+
+func makeBenchmarkURLWithParamStart(paramCount int, genericStart int) *URL {
Review Comment:
```suggestion
func makeBenchmarkURLWithParamStart(paramCount, genericStart int) *URL {
```
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#issuecomment-4678669222
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3399) **Quality Gate passed**
Issues
 [2 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3399&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3399&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3399&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3399&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3399&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3399)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#issuecomment-4678806597
## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3399?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 52.39%. Comparing base ([`e6e14fd`](https://app.codecov.io/gh/apache/dubbo-go/commit/e6e14fd3076a056808a2f844bbc851a23f42865a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`5425ceb`](https://app.codecov.io/gh/apache/dubbo-go/commit/5425cebae940d55a27d69c329a9813f2afba861b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #3399 +/- ##
==========================================
- Coverage 52.40% 52.39% -0.01%
==========================================
Files 492 492
Lines 37785 37785
==========================================
- Hits 19800 19798 -2
- Misses 16380 16383 +3
+ Partials 1605 1604 -1
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/dubbo-go/pull/3399?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Feat: add benchmarks for common.URL [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3399:
URL: https://github.com/apache/dubbo-go/pull/3399#issuecomment-4679501318
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3399) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3399&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3399&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3399&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3399&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3399&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3399)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org