-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fix cloning static query on every query
call
#76
Closed
Comments
alexpovel
added a commit
that referenced
this issue
Jul 28, 2024
A query is static across the entire lifetime of a run. It does not change, but it was `clone()`d on each call to `scope_via_query`, which is expensive. This change constructs the *actually* required `TSQuery` only once (alongside its "negative" counterpart, which also allows later parts to just take a `&TSQuery` instead of `&mut TSQuery`). Closes #76
Merged
alexpovel
added a commit
that referenced
this issue
Jul 28, 2024
A query is static across the entire lifetime of a run. It does not change, but it was `clone()`d on each call to `scope_via_query`, which is expensive. This change constructs the *actually* required `TSQuery` only once (alongside its "negative" counterpart, which also allows later parts to just take a `&TSQuery` instead of `&mut TSQuery`). Closes #76
Results look good now: $ hyperfine --warmup 1 './srgn --gitignored --fail-empty-glob --go comments --files '\''kubernetes/**/*.go'\'' '\''[tT]he (\w+)'\''' './srgn-new --gitignored --fail-empty-glob --go comments --files '\''kubernetes/**/*.go'\'' '\''[tT]he (\w+)'\'''
Benchmark 1: ./srgn --gitignored --fail-empty-glob --go comments --files 'kubernetes/**/*.go' '[tT]he (\w+)'
Time (mean ± σ): 2.307 s ± 0.078 s [User: 23.973 s, System: 1.714 s]
Range (min … max): 2.213 s … 2.439 s 10 runs
Benchmark 2: ./srgn-new --gitignored --fail-empty-glob --go comments --files 'kubernetes/**/*.go' '[tT]he (\w+)'
Time (mean ± σ): 2.015 s ± 0.112 s [User: 20.166 s, System: 1.577 s]
Range (min … max): 1.889 s … 2.216 s 10 runs
Summary
./srgn-new --gitignored --fail-empty-glob --go comments --files 'kubernetes/**/*.go' '[tT]he (\w+)' ran
1.14 ± 0.07 times faster than ./srgn --gitignored --fail-empty-glob --go comments --files 'kubernetes/**/*.go' '[tT]he (\w+)'
where (slow section is no longer even visible) |
This was referenced Aug 18, 2024
This was referenced Sep 29, 2024
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this call would only need to happen a single time, yet it takes up 17% of time:
Source: via
sudo CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --open -F5000 -- --go comments '(\\d+)(\\d)'
inside ofbenches/kubernetes
.Source of problem might be
clone
here:srgn/src/scoping/langs/go.rs
Line 92 in 9a0685c
There is no need to
clone
, as thequery
remains identical through the lifetime of the application. I was just lazy with respect to lifetimes.The text was updated successfully, but these errors were encountered: