lima
lima copied to clipboard
pkg: refactor to compile regexp only once
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.
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]
[^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.
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.
Moving it out of the loops sounds good (if loops are long), not sure about making it global (as mentioned above)
What's the current status?
@alexandear (Off-topic: what's your CNCF slack ID?)
@alexandear (Off-topic: what's your CNCF slack ID?)
https://cloud-native.slack.com/team/U075V4TMQPM