Performance: Hoist regexp.MustCompile out of functions - #29511
Conversation
c6db1ad to
d7f5f7e
Compare
Luap99
left a comment
There was a problem hiding this comment.
Performance wise that actually has the opposite effect for most commands.
Compiling tje regex in the global init scope means every signle command must compile them over and over again, given podman is not a daemon and we run commands over and over again. Most code paths will never need the regex that was compiled so this is wasted time.
This was so bad we had to add our own go.podman.io/storage/pkg/regexp package to delay regex compilation until it is actually needed.
All user must use this, see c2b36be
5bb5eae to
f02ab1a
Compare
|
[NON-BLOCKING] Packit jobs failed. @podman-container-tools/packit-jobs please check. Everyone else, feel free to ignore. |
a853cb4 to
a63f581
Compare
Yes @Honny1 , that's a great point. I went ahead and replaced the simple regexes in |
|
a63f581 to
654d093
Compare
Honny1
left a comment
There was a problem hiding this comment.
I spotted only one issue. Otherwise, we are on good way.
654d093 to
75b7a30
Compare
Replaces regexp.MustCompile with regexp.Delayed from go.podman.io/storage/pkg/regexp for global regular expressions. This avoids compiling regular expressions during the global init scope, improving startup performance for all commands. Tests are kept using regexp.MustCompile where applicable. Fixes: podman-container-tools#29510 Signed-off-by: Vishnu Kothakapu <vishnukothakapu27@gmail.com>
75b7a30 to
e3797d9
Compare
Replaces
regexp.MustCompilewithregexp.Delayedfromgo.podman.io/storage/pkg/regexpfor global regular expressions. This avoids compiling regular expressions during the global init scope, improving startup performance for all commands.Additionally, where possible (such as in quadlet, mac-helper, and ps), the regex engine was stripped entirely and replaced with faster
stringsand loop checks to avoid any regex overhead altogether.Tests are kept using
regexp.MustCompilewhere applicable.Fixes #29510
Checklist
Ensure you have completed the following checklist for your pull request to be reviewed:
commits. (
git commit -s). (If needed, usegit commit -s --amend). The author email must matchthe sign-off email address. See CONTRIBUTING.md
for more information.
Fixes: #29510in commit message (if applicable)make validatepr(format/lint checks)Noneif no user-facing changes)Does this PR introduce a user-facing change?