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

perf: Do not build glob matchers repeatedly when include-exclude feature is enabled #244

Merged

Conversation

osiewicz
Copy link
Contributor

I've noticed in my profiles that if include-exclude feature is enabled, the call to ::iter() function is dominated by path filtering. This commit fixes that by explicitly passing in a premade Globset for a given object.

Note that we're using std::sync::OnceLock to lazily store away premade Globsets, which bumps MSRV to 1.70. An alternative would be to use once_cell as an explicit dependency.

For my use case, in debug builds this takes down the matching time from 650ms to 6ms. I know you shouldn't benchmark debug builds, but rust-embed::iter is on my app's initialization path and that's how I noticed it in the first place. I'd expect release timings to be somewhat similar

…ure is enabled

I've noticed in my profiles that if include-exclude feature is enabled, the call to ::iter() function is dominated by path filtering.
This commit fixes that by explicitly passing in a premade Globset for a given object.

Note that we're using std::sync::OnceLock to lazily store away premade Globsets, which bumps MSRV to 1.70. An alternative would be to use once_cell as an explicit dependency.

For my use case, in debug builds this takes down the matching time from 650ms to 6ms. I know you shouldn't benchmark debug builds, but rust-embed::iter is on my app's initialization path and that's how I noticed it in the first place. I'd expect release timings to be somewhat similar
@pyrossh pyrossh merged commit 36bf70e into pyrossh:master May 11, 2024
5 checks passed
@pyrossh
Copy link
Owner

pyrossh commented May 11, 2024

Nice! LGTM. Thanks @osiewicz.

osiewicz added a commit to zed-industries/zed that referenced this pull request May 11, 2024
RustEmbed repeatedly compiled regexes for handling of 'include='/'exclude' statements in a hot loop, which caused each call to Assets::iter() to take 600ms. Since it is being called twice on our startup path, that alone contributed over a second to startup time in debug builds. I've filed a PR with them pyrossh/rust-embed#244 which brings down the time for a single iter() call to 6ms.
osiewicz added a commit to zed-industries/zed that referenced this pull request May 11, 2024
RustEmbed repeatedly compiled regexes for handling of
'include='/'exclude' statements in a hot loop, which caused each call to
Assets::iter() to take 600ms. Since it is being called twice on our
startup path, that alone contributed over a second to startup time in
debug builds. I've filed a PR with them
pyrossh/rust-embed#244 which brings down the
time for a single iter() call to 6ms.

Release Notes:

- N/A
osiewicz added a commit to RemcoSmitsDev/zed that referenced this pull request May 18, 2024
RustEmbed repeatedly compiled regexes for handling of
'include='/'exclude' statements in a hot loop, which caused each call to
Assets::iter() to take 600ms. Since it is being called twice on our
startup path, that alone contributed over a second to startup time in
debug builds. I've filed a PR with them
pyrossh/rust-embed#244 which brings down the
time for a single iter() call to 6ms.

Release Notes:

- N/A
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.

2 participants