You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "JunLa-0 (via GitHub)" <gi...@apache.org> on 2026/06/12 03:16:34 UTC
[PR] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
JunLa-0 opened a new pull request, #3402:
URL: https://github.com/apache/dubbo-go/pull/3402
Optimize URL equality comparison and map conversion to avoid unnecessary allocations. IsEquals() now compares fields directly instead of materializing two full maps via ToMap(). ToMap() pre-sizes the map and uses a single-pass split for Location parsing.
Fixes: #3248
Signed-off-by: 13927699266@163.com
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#issuecomment-4785245233
@JunLa-0 any progess?
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#discussion_r3401417659
##########
common/url_test.go:
##########
@@ -1507,3 +1507,82 @@ func TestCloneThreadSafe(t *testing.T) {
wg.Wait()
}
+
+// --- Benchmarks for IsEquals and ToMap ---
+
+func BenchmarkIsEquals_SmallParams(b *testing.B) {
+ u1, _ := NewURL("dubbo://127.0.0.1:20000/com.test.Service?key1=value1&key2=value2")
+ u2, _ := NewURL("dubbo://127.0.0.1:20000/com.test.Service?key1=value1&key2=value2")
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ IsEquals(u1, u2)
+ }
+}
+
+func BenchmarkIsEquals_LargeParams(b *testing.B) {
+ base1 := "dubbo://127.0.0.1:20000/com.test.Service?"
+ base2 := "dubbo://127.0.0.1:20000/com.test.Service?"
+ for i := 0; i < 50; i++ {
+ kv := "key" + strconv.Itoa(i) + "=val" + strconv.Itoa(i)
+ if i > 0 {
+ base1 += "&"
+ base2 += "&"
+ }
+ base1 += kv
+ base2 += kv
+ }
+ u1, _ := NewURL(base1)
+ u2, _ := NewURL(base2)
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ IsEquals(u1, u2)
+ }
+}
+
+func BenchmarkIsEquals_WithExcludes(b *testing.B) {
+ u1, _ := NewURL("dubbo://127.0.0.1:20000/com.test.Service?key1=value1&key2=different&key3=value3")
+ u2, _ := NewURL("dubbo://127.0.0.1:20000/com.test.Service?key1=value1&key2=other&key3=value3")
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ IsEquals(u1, u2, "key2")
+ }
+}
+
+func BenchmarkToMap_SmallParams(b *testing.B) {
+ u, _ := NewURL("dubbo://127.0.0.1:20000/com.test.Service?key1=value1&key2=value2")
+ u.Username = "user"
+ u.Password = "pass"
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ _ = u.ToMap()
+ }
+}
+
+func BenchmarkToMap_LargeParams(b *testing.B) {
+ base := "dubbo://127.0.0.1:20000/com.test.Service?"
+ for i := 0; i < 50; i++ {
+ if i > 0 {
+ base += "&"
+ }
+ base += "key" + strconv.Itoa(i) + "=val" + strconv.Itoa(i)
+ }
+ u, _ := NewURL(base)
+ u.Username = "user"
+ u.Password = "pass"
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ _ = u.ToMap()
+ }
+}
+
+func BenchmarkToMap_EmptyParams(b *testing.B) {
+ u := &URL{
+ Protocol: "dubbo",
+ Location: "127.0.0.1:20000",
+ Path: "/com.test.Service",
+ }
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ _ = u.ToMap()
+ }
+}
Review Comment:
不用自己写benchmark 直接复用已有的benchmark 或者在benchmark文件里面添加你需要的benchmark
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#discussion_r3407611122
##########
common/url.go:
##########
@@ -820,7 +820,32 @@ func (c *URL) SetParams(m url.Values) {
// ToMap transfer URL to Map
func (c *URL) ToMap() map[string]string {
- paramsMap := make(map[string]string)
+ c.paramsLock.RLock()
+ paramCount := len(c.params)
+ c.paramsLock.RUnlock()
+
+ fixedCount := 0
+ if c.Protocol != "" {
+ fixedCount++
+ }
+ if c.Username != "" {
+ fixedCount++
+ }
+ if c.Password != "" {
+ fixedCount++
+ }
+ if c.Location != "" {
+ fixedCount += 2 // host + port
+ }
+ if c.Path != "" {
+ fixedCount++
+ }
+
+ if paramCount == 0 && fixedCount == 0 {
+ return nil
+ }
Review Comment:
`ToMap()` releases `paramsLock` before the early-return check, so a concurrent `SetParam/SetParams` can add params between the unlock and the `return nil`, causing `ToMap()` to incorrectly return nil even though params exist. Keep the lock held until the emptiness decision is made (fixedCount can be computed outside the lock).
##########
common/url.go:
##########
@@ -1019,23 +1038,76 @@ func IsEquals(left *URL, right *URL, excludes ...string) bool {
return false
}
- leftMap := left.ToMap()
- rightMap := right.ToMap()
- for _, exclude := range excludes {
- delete(leftMap, exclude)
- delete(rightMap, exclude)
+ // Build a small lookup set for excluded keys to avoid repeated linear scans
+ // and to avoid materializing two full maps just for comparison.
+ var excludeSet map[string]struct{}
+ if len(excludes) > 0 {
+ excludeSet = make(map[string]struct{}, len(excludes))
+ for _, k := range excludes {
+ excludeSet[k] = struct{}{}
+ }
}
- if len(leftMap) != len(rightMap) {
- return false
+ isExcluded := func(key string) bool {
+ if excludeSet == nil {
+ return false
+ }
+ _, ok := excludeSet[key]
+ return ok
}
- for lk, lv := range leftMap {
- if rv, ok := rightMap[lk]; !ok {
+ // Compare scalar fields directly.
+ if left.Protocol != right.Protocol && !isExcluded(PROTOCOL) {
+ return false
+ }
+ if left.Username != right.Username && !isExcluded("username") {
+ return false
+ }
+ if left.Password != right.Password && !isExcluded("password") {
+ return false
+ }
+ if left.Path != right.Path && !isExcluded("path") {
+ return false
+ }
+ if left.Location != right.Location {
+ if isExcluded("host") && isExcluded("port") {
+ // Both excluded, skip Location comparison
+ } else if isExcluded("host") || isExcluded("port") {
+ // Only one side of host:port excluded — fall through to param comparison
Review Comment:
When only one of `host` or `port` is excluded and `left.Location != right.Location`, the current code intentionally "falls through" but never compares the non-excluded component. That can incorrectly treat URLs as equal even though the non-excluded host/port differs.
##########
common/url.go:
##########
@@ -839,24 +864,18 @@ func (c *URL) ToMap() map[string]string {
paramsMap["password"] = c.Password
}
if c.Location != "" {
- paramsMap["host"] = strings.Split(c.Location, ":")[0]
- var port string
- if strings.Contains(c.Location, ":") {
- port = strings.Split(c.Location, ":")[1]
+ // Single-pass split avoids repeated string scanning.
+ parts := strings.Split(c.Location, ":")
+ paramsMap["host"] = parts[0]
+ if len(parts) > 1 {
+ paramsMap["port"] = parts[len(parts)-1]
Review Comment:
`ToMap()` currently uses `strings.Split(c.Location, ":")` and then takes the last element as port. This both allocates and changes behavior vs the previous implementation for locations containing multiple ':' (e.g. IPv6 or multiple endpoints). If the goal is to preserve existing semantics while reducing allocations, parse host/port without allocating and keep port as the segment between the first and second ':' (or "0" when missing).
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#issuecomment-4903916504
@JunLa-0 any progess? If no further update, this pr will be closed and we will assign others to work on this.
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#discussion_r3401417659
##########
common/url_test.go:
##########
@@ -1507,3 +1507,82 @@ func TestCloneThreadSafe(t *testing.T) {
wg.Wait()
}
+
+// --- Benchmarks for IsEquals and ToMap ---
+
+func BenchmarkIsEquals_SmallParams(b *testing.B) {
+ u1, _ := NewURL("dubbo://127.0.0.1:20000/com.test.Service?key1=value1&key2=value2")
+ u2, _ := NewURL("dubbo://127.0.0.1:20000/com.test.Service?key1=value1&key2=value2")
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ IsEquals(u1, u2)
+ }
+}
+
+func BenchmarkIsEquals_LargeParams(b *testing.B) {
+ base1 := "dubbo://127.0.0.1:20000/com.test.Service?"
+ base2 := "dubbo://127.0.0.1:20000/com.test.Service?"
+ for i := 0; i < 50; i++ {
+ kv := "key" + strconv.Itoa(i) + "=val" + strconv.Itoa(i)
+ if i > 0 {
+ base1 += "&"
+ base2 += "&"
+ }
+ base1 += kv
+ base2 += kv
+ }
+ u1, _ := NewURL(base1)
+ u2, _ := NewURL(base2)
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ IsEquals(u1, u2)
+ }
+}
+
+func BenchmarkIsEquals_WithExcludes(b *testing.B) {
+ u1, _ := NewURL("dubbo://127.0.0.1:20000/com.test.Service?key1=value1&key2=different&key3=value3")
+ u2, _ := NewURL("dubbo://127.0.0.1:20000/com.test.Service?key1=value1&key2=other&key3=value3")
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ IsEquals(u1, u2, "key2")
+ }
+}
+
+func BenchmarkToMap_SmallParams(b *testing.B) {
+ u, _ := NewURL("dubbo://127.0.0.1:20000/com.test.Service?key1=value1&key2=value2")
+ u.Username = "user"
+ u.Password = "pass"
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ _ = u.ToMap()
+ }
+}
+
+func BenchmarkToMap_LargeParams(b *testing.B) {
+ base := "dubbo://127.0.0.1:20000/com.test.Service?"
+ for i := 0; i < 50; i++ {
+ if i > 0 {
+ base += "&"
+ }
+ base += "key" + strconv.Itoa(i) + "=val" + strconv.Itoa(i)
+ }
+ u, _ := NewURL(base)
+ u.Username = "user"
+ u.Password = "pass"
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ _ = u.ToMap()
+ }
+}
+
+func BenchmarkToMap_EmptyParams(b *testing.B) {
+ u := &URL{
+ Protocol: "dubbo",
+ Location: "127.0.0.1:20000",
+ Path: "/com.test.Service",
+ }
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ _ = u.ToMap()
+ }
+}
Review Comment:
不用自己写benchmark 直接复用已有的benchmark
##########
common/url.go:
##########
@@ -1019,23 +1038,76 @@ func IsEquals(left *URL, right *URL, excludes ...string) bool {
return false
}
- leftMap := left.ToMap()
- rightMap := right.ToMap()
- for _, exclude := range excludes {
- delete(leftMap, exclude)
- delete(rightMap, exclude)
+ // Build a small lookup set for excluded keys to avoid repeated linear scans
+ // and to avoid materializing two full maps just for comparison.
+ var excludeSet map[string]struct{}
+ if len(excludes) > 0 {
+ excludeSet = make(map[string]struct{}, len(excludes))
+ for _, k := range excludes {
+ excludeSet[k] = struct{}{}
+ }
}
- if len(leftMap) != len(rightMap) {
- return false
+ isExcluded := func(key string) bool {
+ if excludeSet == nil {
+ return false
+ }
+ _, ok := excludeSet[key]
+ return ok
}
Review Comment:
This rewrite seems more complicated than necessary, and it also changes the original comparison semantics.
The old implementation compares the result of ToMap(), so excluding only "port" should still compare "host", and excluding only "host" should still compare "port". In the new logic, when left.Location != right.Location and only one of host/port is excluded, the code falls through to param comparison, but it never compares the remaining non-excluded part of Location.
For example, these should not be equal when only "port" is excluded:
left.Location = "10.0.0.1:20880"
right.Location = "10.0.0.2:20880"
IsEquals(left, right, "port")
Besides that, the code still materializes leftParams, so the optimization is not as simple as "avoid materializing maps"; it only avoids building two full ToMap() results. I suggest either keeping the original map-based comparison for correctness, or splitting host/port explicitly and comparing only the non-excluded fields.
##########
common/url.go:
##########
@@ -1019,23 +1038,76 @@ func IsEquals(left *URL, right *URL, excludes ...string) bool {
return false
}
- leftMap := left.ToMap()
- rightMap := right.ToMap()
- for _, exclude := range excludes {
- delete(leftMap, exclude)
- delete(rightMap, exclude)
+ // Build a small lookup set for excluded keys to avoid repeated linear scans
+ // and to avoid materializing two full maps just for comparison.
+ var excludeSet map[string]struct{}
+ if len(excludes) > 0 {
+ excludeSet = make(map[string]struct{}, len(excludes))
+ for _, k := range excludes {
+ excludeSet[k] = struct{}{}
+ }
}
- if len(leftMap) != len(rightMap) {
- return false
+ isExcluded := func(key string) bool {
+ if excludeSet == nil {
+ return false
+ }
+ _, ok := excludeSet[key]
+ return ok
}
- for lk, lv := range leftMap {
- if rv, ok := rightMap[lk]; !ok {
+ // Compare scalar fields directly.
+ if left.Protocol != right.Protocol && !isExcluded(PROTOCOL) {
+ return false
+ }
+ if left.Username != right.Username && !isExcluded("username") {
+ return false
+ }
+ if left.Password != right.Password && !isExcluded("password") {
+ return false
+ }
+ if left.Path != right.Path && !isExcluded("path") {
+ return false
+ }
+ if left.Location != right.Location {
+ if isExcluded("host") && isExcluded("port") {
+ // Both excluded, skip Location comparison
+ } else if isExcluded("host") || isExcluded("port") {
+ // Only one side of host:port excluded — fall through to param comparison
+ } else {
return false
- } else if lv != rv {
+ }
+ }
Review Comment:
`IsEquals` 在只 exclude `host` 或 `port` 时会漏比较另一半 location
PR 里当 `left.Location != right.Location` 且只排除 `host` 或 `port` 其中一个时,代码直接“fall through”,但后面只比较 params,不再比较未被排除的 host/port。
你试一下`Location: 10.0.0.1:20880` vs `10.0.0.2:20880`,exclude `port` 后 PR 返回 `true`,base 返回 `false`。
##########
common/url.go:
##########
@@ -839,24 +864,18 @@ func (c *URL) ToMap() map[string]string {
paramsMap["password"] = c.Password
}
if c.Location != "" {
- paramsMap["host"] = strings.Split(c.Location, ":")[0]
- var port string
- if strings.Contains(c.Location, ":") {
- port = strings.Split(c.Location, ":")[1]
+ // Single-pass split avoids repeated string scanning.
+ parts := strings.Split(c.Location, ":")
+ paramsMap["host"] = parts[0]
+ if len(parts) > 1 {
+ paramsMap["port"] = parts[len(parts)-1]
} else {
- port = "0"
+ paramsMap["port"] = "0"
}
Review Comment:
`ToMap` 的多地址 port 解析语义被改了
原逻辑对 `127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183` 的 `port` 是 `2181,127.0.0.1` 确实不合理,
PR 改成取最后一个 `:` 后的 `2183`。也不合理
这里改一下,然后在pr简介里面说明
##########
common/url.go:
##########
@@ -820,7 +820,32 @@ func (c *URL) SetParams(m url.Values) {
// ToMap transfer URL to Map
func (c *URL) ToMap() map[string]string {
- paramsMap := make(map[string]string)
+ c.paramsLock.RLock()
+ paramCount := len(c.params)
+ c.paramsLock.RUnlock()
+
+ fixedCount := 0
+ if c.Protocol != "" {
+ fixedCount++
+ }
+ if c.Username != "" {
+ fixedCount++
+ }
+ if c.Password != "" {
+ fixedCount++
+ }
+ if c.Location != "" {
+ fixedCount += 2 // host + port
+ }
+ if c.Path != "" {
+ fixedCount++
+ }
+
+ if paramCount == 0 && fixedCount == 0 {
+ return nil
+ }
+
+ paramsMap := make(map[string]string, paramCount+fixedCount)
Review Comment:
- `paramCount` 单独加锁读一次,后面 `RangeParams` 又加锁遍历一次,多了一次锁操作。
- 这不是一致性快照:两次锁之间 params 可能变,容量估算可能不准。
- `fixedCount` 只是容量估算,不影响逻辑;估多了也只是多分一点内存。
- 如果 params 里本来就有 `protocol`、`host`、`port` 这些 key,后面的固定字段会覆盖它们,`fixedCount` 仍然按新增 key 算,容量也会估大。
- 性能收益主要来自预分配,但可读性代价有点高。
建议就是保留容量估算,去掉无意义初始化,并确保 `protocol/location` 行为不变。
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#discussion_r3401407882
##########
common/url.go:
##########
@@ -839,24 +864,18 @@ func (c *URL) ToMap() map[string]string {
paramsMap["password"] = c.Password
}
if c.Location != "" {
- paramsMap["host"] = strings.Split(c.Location, ":")[0]
- var port string
- if strings.Contains(c.Location, ":") {
- port = strings.Split(c.Location, ":")[1]
+ // Single-pass split avoids repeated string scanning.
+ parts := strings.Split(c.Location, ":")
+ paramsMap["host"] = parts[0]
+ if len(parts) > 1 {
+ paramsMap["port"] = parts[len(parts)-1]
} else {
- port = "0"
+ paramsMap["port"] = "0"
}
Review Comment:
`ToMap` 的多地址 port 解析语义被改了
原逻辑对 `127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183` 的 `port` 是 `2181,127.0.0.1` 确实不合理,
PR 改成取最后一个 `:` 后的 `2183`。也不合理
这里改成合理的逻辑,然后在pr简介里面说明
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "ywxzm03 (via GitHub)" <gi...@apache.org>.
ywxzm03 commented on code in PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#discussion_r3402699246
##########
common/url.go:
##########
@@ -1019,23 +1038,76 @@ func IsEquals(left *URL, right *URL, excludes ...string) bool {
return false
}
- leftMap := left.ToMap()
- rightMap := right.ToMap()
- for _, exclude := range excludes {
- delete(leftMap, exclude)
- delete(rightMap, exclude)
+ // Build a small lookup set for excluded keys to avoid repeated linear scans
+ // and to avoid materializing two full maps just for comparison.
+ var excludeSet map[string]struct{}
+ if len(excludes) > 0 {
+ excludeSet = make(map[string]struct{}, len(excludes))
+ for _, k := range excludes {
+ excludeSet[k] = struct{}{}
+ }
}
- if len(leftMap) != len(rightMap) {
- return false
+ isExcluded := func(key string) bool {
+ if excludeSet == nil {
+ return false
+ }
+ _, ok := excludeSet[key]
+ return ok
}
- for lk, lv := range leftMap {
- if rv, ok := rightMap[lk]; !ok {
+ // Compare scalar fields directly.
+ if left.Protocol != right.Protocol && !isExcluded(PROTOCOL) {
+ return false
+ }
+ if left.Username != right.Username && !isExcluded("username") {
+ return false
+ }
+ if left.Password != right.Password && !isExcluded("password") {
+ return false
+ }
+ if left.Path != right.Path && !isExcluded("path") {
+ return false
+ }
+ if left.Location != right.Location {
+ if isExcluded("host") && isExcluded("port") {
+ // Both excluded, skip Location comparison
+ } else if isExcluded("host") || isExcluded("port") {
+ // Only one side of host:port excluded — fall through to param comparison
+ } else {
return false
- } else if lv != rv {
+ }
+ }
+
+ // Compare params directly without materializing maps.
+ // Build left params (excluding filtered keys), then verify right matches.
+ leftParams := make(map[string]string)
Review Comment:
这里可以做个容量预估,len(left.params) 就有了
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#issuecomment-4687033832
## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3402?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `77.41935%` with `14 lines` in your changes missing coverage. Please review.
: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 ([`6a5d4c4`](https://app.codecov.io/gh/apache/dubbo-go/commit/6a5d4c40dfe5c7b2d2b3dbb66b445c64f4bdf7e2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/dubbo-go/pull/3402?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [common/url.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3402?src=pr&el=tree&filepath=common%2Furl.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3VybC5nbw==) | 77.41% | [8 Missing and 6 partials :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3402?src=pr&el=tree&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 #3402 +/- ##
==========================================
- Coverage 52.40% 52.39% -0.01%
==========================================
Files 492 492
Lines 37785 37826 +41
==========================================
+ Hits 19800 19819 +19
- Misses 16380 16395 +15
- Partials 1605 1612 +7
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/dubbo-go/pull/3402?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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#issuecomment-4687070091
@ywxzm03 help review this
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "JunLa-0 (via GitHub)" <gi...@apache.org>.
JunLa-0 closed pull request #3402: perf: optimize IsEquals and ToMap to reduce allocations
URL: https://github.com/apache/dubbo-go/pull/3402
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#issuecomment-4687063278
the target branch should be 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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl closed pull request #3402: perf: optimize IsEquals and ToMap to reduce allocations
URL: https://github.com/apache/dubbo-go/pull/3402
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#issuecomment-4687007072
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3402) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3402&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3402&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3402&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3402&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3402&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=3402)
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#issuecomment-4687012499
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3402) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3402&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3402&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3402&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3402&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3402&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=3402)
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#issuecomment-4956506933
close via #3488
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#discussion_r3410654905
##########
common/url.go:
##########
@@ -1019,23 +1038,76 @@ func IsEquals(left *URL, right *URL, excludes ...string) bool {
return false
}
- leftMap := left.ToMap()
- rightMap := right.ToMap()
- for _, exclude := range excludes {
- delete(leftMap, exclude)
- delete(rightMap, exclude)
+ // Build a small lookup set for excluded keys to avoid repeated linear scans
+ // and to avoid materializing two full maps just for comparison.
+ var excludeSet map[string]struct{}
+ if len(excludes) > 0 {
+ excludeSet = make(map[string]struct{}, len(excludes))
+ for _, k := range excludes {
+ excludeSet[k] = struct{}{}
+ }
}
- if len(leftMap) != len(rightMap) {
- return false
+ isExcluded := func(key string) bool {
+ if excludeSet == nil {
+ return false
+ }
+ _, ok := excludeSet[key]
+ return ok
}
- for lk, lv := range leftMap {
- if rv, ok := rightMap[lk]; !ok {
+ // Compare scalar fields directly.
+ if left.Protocol != right.Protocol && !isExcluded(PROTOCOL) {
+ return false
+ }
+ if left.Username != right.Username && !isExcluded("username") {
+ return false
+ }
+ if left.Password != right.Password && !isExcluded("password") {
+ return false
+ }
+ if left.Path != right.Path && !isExcluded("path") {
+ return false
+ }
+ if left.Location != right.Location {
Review Comment:
[P1] 这里把 `host` / `port` 的排除逻辑挂在整条 `Location` 上了:只传 `host` 或只传 `port` 时,`left.Location != right.Location` 也会直接落入“放行”分支,另一半地址差异被一并忽略。旧实现是按 `ToMap()` 删除单个 key 比较,两个字段的排除语义是独立的。请分别比较 host/port,或保留原来的按键删除语义。
--
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] perf: optimize IsEquals and ToMap to reduce allocations [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #3402:
URL: https://github.com/apache/dubbo-go/pull/3402#issuecomment-4687088524
update to latest develop and run https://github.com/apache/dubbo-go/blob/develop/common/url_benchmark_test.go to see the performance shift before and after you commit, and paste the result comparison here
--
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