Skip to content

Replace copier.Copy with optimized manual deep copy in URL.Clone (#2678)#2798

Closed
Nexusrex18 wants to merge 1 commit intoapache:mainfrom
Nexusrex18:issue2678
Closed

Replace copier.Copy with optimized manual deep copy in URL.Clone (#2678)#2798
Nexusrex18 wants to merge 1 commit intoapache:mainfrom
Nexusrex18:issue2678

Conversation

@Nexusrex18
Copy link
Contributor

Fixes by replacing copier.Copy with a manual deep copy in URL.Clone(), optimized with pre-allocated maps for params and attributes. This reduces memory and CPU overhead, especially for large data volumes.
Key changes:

  • Replaced copier.Copy with manual implementation in URL.Clone().
  • Removed github.com/jinzhu/copier import from url.go and dependency from go.mod via go mod tidy.
  • Added TestSubURLCopy to verify deep-copy behavior.
  • Updated BenchmarkClone to test the new implementation.

Benchmarks:

  • 100 params/attributes:
    • Old (copier): 51 µs/op, 23.74 KB/op, 222 allocs/op
    • New (manual): 26 µs/op, 14.12 KB/op, 112 allocs/op
  • 1,000 params/attributes:
    • Old (copier): 428 µs/op, 228 KB/op, 1,142 allocs/op
    • New (manual): 270 µs/op, 197 KB/op, 1,010 allocs/op

The new implementation is faster (~1.6x at 1,000 entries, ~2x at 100), uses less memory (~14% at 1,000, ~40% at 100), and reduces allocations (~12% at 1,000, ~50% at 100).

Note: Unrelated test failures in rpc_service_test.go (e.g., unexported testService) were observed but pre-exist this change and are outside this PR’s scope.

Fixes: #2678

Tested with:

  • go test -v -run TestSubURLCopy: Passed
  • go test -bench=BenchmarkClone -benchmem: Confirmed performance

Signed-off-by: Nexusrex18 <lavisnj350@gmail.com>
@sonarqubecloud
Copy link

@Nexusrex18 Nexusrex18 closed this Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Url.Clone

1 participant