-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/policy/policy: Optimize SearchContext String()
Use strings.Builder instead of fmt.Sprintf() and preallocate the size of the string so that Go doesn't need to over-allocate if the string ends up longer than what the buffer growth algorithm predicts. issue reference : #19571 Result: ``` $ go test -v -run '^$' -bench 'BenchmarkSearchContextString' -benchmem ./pkg/policy > BenchmarkSearchContextString_old.txt $ go test -v -run '^$' -bench 'BenchmarkSearchContextString' -benchmem ./pkg/policy > BenchmarkSearchContextString_new.txt $ benchcmp BenchmarkSearchContextString_old.txt BenchmarkSearchContextString_new.txt benchmark old ns/op new ns/op delta BenchmarkSearchContextString-2 9336 5106 -45.31% benchmark old allocs new allocs delta BenchmarkSearchContextString-2 77 47 -38.96% benchmark old bytes new bytes delta BenchmarkSearchContextString-2 2736 1848 -32.46% ``` Signed-off-by: MikeLing <sabergeass@gmail.com>
- Loading branch information
Showing
2 changed files
with
117 additions
and
12 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