-
Notifications
You must be signed in to change notification settings - Fork 127
Optimize fields validation #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit that I didn't expect it to happen. Good catch!
|
I have refactored the code to don't need regular expressions, I see similar improvements in time than using a regular expressions cache. |
|
I found profiling that Shared profile with current code: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice optimization, although the code readability might be impaired a bit. Do you think that you can get rid of "regexp" dependency here at all?
Before merging this PR, I suggest releasing a new minor version, so we can easily roll back if this PR becomes problematic.
| func compareKeys(key string, def FieldDefinition, searchedKey string) bool { | ||
| k := strings.ReplaceAll(key, ".", "\\.") | ||
| k = strings.ReplaceAll(k, "*", "[^.]+") | ||
| // Loop over every byte in `key` to find if there is a matching byte in `searchedKey`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that we need some unit tests as it looks like a custom logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that we already had good coverage for this, but adding a unit test has helped me found some wrong cases with wildcards. Good idea, thanks 👍
Well, this is relative, others may also find counterintuitive to build regular expressions on the fly 🙂 In any case the code is quite localized inside a single function with well-defined expectations. I have added comments in case it helps.
The other case where we use
👍 |
|
/test |
|
/test |
1 similar comment
|
/test |
While trying some changes in pipeline tests I found that testing some packages was taking much more time than I would have expected.
I have enabled profiling and I have found that most of the time,
elastic-packageis compiling regular expressions.Refactoring the code to don't use regular expressions drastically improves the execution times. For example in the case of the
panwmodule it goes in my laptop from more than 3 minutes to less than 10 seconds.