-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Speedup AccessAfterLifetime.ql
#20843
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
Rust: Speedup AccessAfterLifetime.ql
#20843
Conversation
1e2c798 to
8455663
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the AccessAfterLifetime.ql query to improve performance by 58% on total Rust analysis time. The optimization is achieved by moving filtering logic from a helper predicate that was called during dataflow analysis into the isSource and isSink predicates, which reduces the scope of the dataflow computation.
Key changes:
- Moved macro expansion and unsafe block filtering from
narrowDereferenceAfterLifetimetoisSourceandisSinkpredicates - Removed the
narrowDereferenceAfterLifetimehelper predicate - Simplified the query logic by calling
AccessAfterLifetime::dereferenceAfterLifetimedirectly
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rust/ql/src/queries/security/CWE-825/AccessAfterLifetime.ql | Refactored filtering logic to move constraints into source/sink predicates for better performance |
| rust/ql/test/query-tests/security/CWE-825/AccessAfterLifetime.expected | Updated test expectations to reflect filtered results (macro expansions and non-unsafe dereferences) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
paldepind
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
If I understand correctly this shouldn't change the results. But now the filtering that only depends on sources/sinks is simply done before the data flow library does any work, instead of after, and thus we get the performance improvement.
Correct. |
|
Oh wow, good spot. 6.2% average analysis speedup across all projects 🚀 The new code also reads cleaner to me. 👍 |
DCA shows a massive 58 % total analysis time speedup on
rust.