chaojixinren opened a new pull request, #3487:
URL: https://github.com/apache/dubbo-go/pull/3487
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 single-pass
Location parsing with IndexByte.
## Benchmark Results
### ToMap Performance
| Params | Before (ns/op) | After (ns/op) | Improvement | Before (B/op) |
After (B/op) | Alloc Reduction |
|--------|----------------|---------------|-------------|---------------|--------------|-----------------|
| 1 | 377.8 | 233.0 | **38.3%** | 1016 |
664 | **34.6%** |
| 32 | 1775 | 893.5 | **49.7%** | 4536 |
2392 | **47.3%** |
| 256 | 13499 | 6275 | **53.5%** | 37400 |
18520 | **50.5%** |
| 1024 | 55351 | 23996 | **56.7%** | 160393 |
82048 | **48.9%** |
### IsEquals Performance
| Params | Before (ns/op) | After (ns/op) | Improvement | Before (B/op) |
After (B/op) | Alloc Reduction |
|--------|----------------|---------------|-------------|---------------|--------------|-----------------|
| 1 | 954.6 | 228.8 | **76.0%** | 2032 | 0
| **100%** |
| 32 | 4556 | 2432 | **46.6%** | 9072 |
4136 | **54.4%** |
| 256 | 32396 | 19433 | **40.0%** | 74800 |
37000 | **50.5%** |
| 1024 | 129318 | 78003 | **39.7%** | 320786 |
159992 | **50.1%** |
## Key Changes
1. **ToMap optimization**:
- Pre-size map allocation based on param count + scalar fields
- Use `IndexByte` for single-pass Location parsing (zero allocations)
- Remove duplicate Protocol assignment
2. **IsEquals optimization**:
- Compare scalar fields directly
- Compare params without materializing full maps
- Extract `parseLocation` helper function for code reuse
## Testing
- All existing tests pass: `go test ./common`
- Benchmark improvements verified with `-benchmem` flag
Fixes: #3394
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]