[v17] Improve performance of utils.ReplaceRegexp#51935
Merged
rosstimothy merged 1 commit intobranch/v17from Feb 7, 2025
Merged
[v17] Improve performance of utils.ReplaceRegexp#51935rosstimothy merged 1 commit intobranch/v17from
rosstimothy merged 1 commit intobranch/v17from
Conversation
The main changes here are: - Using an LRU cache to store compiled regular expressions. - Removing stack traces captured by trace.NotFound/trace.Wrap when there are no matches. This was heavily inspired by #23534 which made similar changes to improve the performance of utils.MatchString. The main beneficiaries of this change are services.MapRoles and services.TraitsToRoles which rely heavily on utils.ReplaceRegexp, utils.RegexpWithConfig, or ReplaceRegexpWith. BenchmarkReplaceRegexp was added to validate the improvements in this change and prevent regressions in the future. Results from before and after this change: benchstat old.txt new.txt goos: darwin goarch: arm64 pkg: github.com/gravitational/teleport/lib/utils cpu: Apple M2 Pro │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ ReplaceRegexp/same_expression-12 29.527µ ± 12% 6.837µ ± 1% -76.84% (p=0.000 n=10) ReplaceRegexp/unique_expressions-12 22.94µ ± 1% 25.10µ ± 1% +9.41% (p=0.002 n=10) ReplaceRegexp/no_matches-12 24.692µ ± 3% 2.861µ ± 1% -88.41% (p=0.000 n=10) geomean 25.57µ 7.889µ -69.15% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ ReplaceRegexp/same_expression-12 22071.5 ± 1% 164.0 ± 0% -99.26% (p=0.000 n=10) ReplaceRegexp/unique_expressions-12 12.90Ki ± 1% 12.87Ki ± 0% ~ (p=0.165 n=10) ReplaceRegexp/no_matches-12 14257.00 ± 1% 15.00 ± 0% -99.89% (p=0.000 n=10) geomean 15.70Ki 318.8 -98.02% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ ReplaceRegexp/same_expression-12 58.000 ± 0% 6.000 ± 0% -89.66% (p=0.000 n=10) ReplaceRegexp/unique_expressions-12 55.00 ± 0% 55.00 ± 0% ~ (p=1.000 n=10) ¹ ReplaceRegexp/no_matches-12 58.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10) geomean 56.98 ? ² ³ ¹ all samples are equal ² summaries must be >0 to compute geomean ³ ratios must be >0 to compute geomean
marcoandredinis
approved these changes
Feb 7, 2025
espadolini
approved these changes
Feb 7, 2025
Merged
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport #51872 to branch/v17
changelog: Reduce CPU consumption required to map roles between clusters and perform trait to role resolution.