Skip to content
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

pkg: move regexp compilation out of loops #2331

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

alexandear
Copy link
Member

@alexandear alexandear commented May 8, 2024

This PR moves regexps out of for loops to recompile only once per function call.

@jandubois
Copy link
Member

to prevent it from being recompiled each time these functions are called

All these regexes are only used once, or very few times, so the time spent recompiling them is immaterial.1

On the other hand, you now introduce additional global variables with longer names in a wider scope, and the actual text of the regex is now further away in the source code from the location where is being used.

Making the code even slightly harder to understand/maintain is not worth it to me to get a non-noticeable performance gain.

I don't feel strongly about this particular instance, so I'll leave it to other maintainers to decide if they want to accept this change.

Footnotes

  1. And if you are using VZ emulation instead of QEMU, then you now compile a regex that otherwise you wouldn't. Others may also be unused, depending on the subcommand you are running. None of this matters, of course.

@alexandear alexandear force-pushed the refactor/move-out-regexp branch from a74edea to e558941 Compare May 9, 2024 08:22
@afbjorklund
Copy link
Member

Moving it out of the loops sounds good (if loops are long), not sure about making it global (as mentioned above)

@AkihiroSuda
Copy link
Member

What's the current status?

@AkihiroSuda
Copy link
Member

@alexandear (Off-topic: what's your CNCF slack ID?)

jandubois
jandubois previously approved these changes May 30, 2024
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I wrote before, I'm not sure if creating global variables for regular expressions that are likely only compiled once per program run is an improvement, but at least the definition is still reasonably close to the location where it is used.

If other @lima-vm/maintainers want to merge, then I'm fine with it.

@alexandear alexandear force-pushed the refactor/move-out-regexp branch from e558941 to 93a8a3a Compare May 30, 2024 17:26
@alexandear alexandear changed the title pkg: refactor to compile regexp only once pkg: move regexp compilation out from loops May 30, 2024
@alexandear alexandear changed the title pkg: move regexp compilation out from loops pkg: move regexp compilation out of loops May 30, 2024
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

@alexandear
Copy link
Member Author

@alexandear (Off-topic: what's your CNCF slack ID?)

https://cloud-native.slack.com/team/U075V4TMQPM

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda requested a review from afbjorklund May 30, 2024 17:41
@jandubois jandubois added this to the v0.23.0 (tentative) milestone May 30, 2024
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
@alexandear alexandear force-pushed the refactor/move-out-regexp branch from 93a8a3a to bfb90fa Compare June 11, 2024 09:40
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 916a01f into lima-vm:master Jun 11, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants