Optimize trait loop evaluation#19097
Conversation
|
Might be nice to add a benchmark here as well, which would show how much of an improvement this change makes, as well as make it easier to detect performance regressions in the future. |
+1 , let's get some numbers in. It's hard to assess how well this works just by reading it. |
|
|
||
| // warn at most maxMismatchedTraitValuesWarned trait values to prevent huge warning lines | ||
| if len(mismatched) > maxMismatchedTraitValuesWarned { | ||
| warnings = append(warnings, fmt.Sprintf( |
There was a problem hiding this comment.
I know I suggested adding this to the returned warnings myself but now that I'm thinking about it again I wonder if we'll only be increasing amount of log noise this way - because these returned warnings are logged at "warn" level on the caller's side. I think we should just log these "mismatched" traits locally in this method and keep it at debug.
There was a problem hiding this comment.
I had similar thoughts here. +1.
Co-authored-by: Alan Parra <alan.parra@goteleport.com>
codingllama
left a comment
There was a problem hiding this comment.
Code looks reasonable. @vitorenesduarte, could you provide some measurements and maybe add a Go benchmark test, so we have data behind the PR? Other than that, happy to stamp it.
| } | ||
|
|
||
|
|
||
| /* |
There was a problem hiding this comment.
There's no need to include this comment in the source code, but it would be nice to see a before/after in the PR description. You can use golang.org/x/perf/cmd/benchstat to generate a nice diff.
There was a problem hiding this comment.
I saw results like these in other benchmarks. Removed in 7eaa6ea.
Thanks for suggesting benchstat!!
|
@zmb3 @codingllama ce86dc0 adds a benchmark using the test cases we already had for I ran the benchmark both with |
| } | ||
|
|
||
|
|
||
| /* |
There was a problem hiding this comment.
nit: Remove the comment with benchmark results - it's better to run it again if necessary.
Many thanks! LGTM. |
|
@vitorenesduarte See the table below for backport results.
|
This commit reduces the number of `log.Debug`s in the trait loop evaluation in case of a mismatch. This commit also optimizes the trait eval loop ensuring that each regexp is compiled at-most once, and only if strictly needed.
* Refactor tests under services package. Refactored all tests under "lib/services/suite" to use testify instead of gocheck. * Optimize trait loop evaluation (#19097) This commit reduces the number of `log.Debug`s in the trait loop evaluation in case of a mismatch. This commit also optimizes the trait eval loop ensuring that each regexp is compiled at-most once, and only if strictly needed. Co-authored-by: Russell Jones <rjones@goteleport.com>
This commit reduces the number of `log.Debug`s in the trait loop evaluation in case of a mismatch. This commit also optimizes the trait eval loop ensuring that each regexp is compiled at-most once, and only if strictly needed.
* Refactor tests under services package. Refactored all tests under "lib/services/suite" to use testify instead of gocheck. * Optimize trait loop evaluation (#19097) This commit reduces the number of `log.Debug`s in the trait loop evaluation in case of a mismatch. This commit also optimizes the trait eval loop ensuring that each regexp is compiled at-most once, and only if strictly needed. Co-authored-by: Russell Jones <rjones@goteleport.com>
* Refactor tests under services package. Refactored all tests under "lib/services/suite" to use testify instead of gocheck. * Optimize trait loop evaluation (#19097) This commit reduces the number of `log.Debug`s in the trait loop evaluation in case of a mismatch. This commit also optimizes the trait eval loop ensuring that each regexp is compiled at-most once, and only if strictly needed. Co-authored-by: Russell Jones <rjones@goteleport.com>
Fixes #18973.
This PR reduces the number of
log.Debugs in the trait loop evaluation in case of a mismatch.This PR also optimizes the trait eval loop ensuring that each regexp is compiled at-most once, and only if strictly needed.
Testing
None, besides the existing/updated unit tests.
Benchmark
go test:go test -v: