-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize/new route regexp allocations (#732)
## What type of PR is this? (check all applicable) - [x] Refactor - [ ] Feature - [ ] Bug Fix - [x] Optimization - [ ] Documentation Update ## Description This optimizes NewRouter creation. The change introduces strings.Builder for more efficient strings concatenation, and replaces SplitN with Index, avoiding the allocations for the slice. ## Related Tickets & Documents | Test Group | Condition | Average Time (ns/op) | Average Memory (B/op) | Average Allocations | |-----------------------------|-----------|----------------------|-----------------------|---------------------| | **BenchmarkNewRouter** | Before | 37041 | 26553 | 376 | | | After | 32046 | 25800 | 347 | | **BenchmarkNewRouterRegexpFunc** | Before | 4713 | 2385 | 75 | | | After | 2792 | 1640 | 46 | BenchmarkNewRouterRegexpFunc: Time Improvement: Significant improvement in execution time from 4,713 ns/op to 2,792 ns/op. Memory Usage: Memory usage per operation dropped from 2,385 bytes to 1,640 bytes. Allocations: Allocations per operation decreased substantially from 75 to 46. ## Added/updated tests? - [x] Yes ## Run verifications and test - [ ] `make verify` is passing - [x] `make test` is passing --------- Co-authored-by: Tit Petric <[email protected]>
- Loading branch information
Showing
2 changed files
with
67 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters