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: refactor to compile regexp only once #2331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexandear
Copy link
Contributor

@alexandear alexandear commented May 8, 2024

This PR moves the compiled regexp outside the functions to prevent it from being recompiled each time these functions are called. Some regexp moved out of loops to save readability.

@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.

Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
@afbjorklund
Copy link
Contributor

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

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.

None yet

3 participants