C++: Speed up cpp/leap-year/unchecked-after-arithmetic-year-modification#21768
Open
C++: Speed up cpp/leap-year/unchecked-after-arithmetic-year-modification#21768
cpp/leap-year/unchecked-after-arithmetic-year-modification#21768Conversation
…er an initial round of the query to reduce the number of sinks.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a severe performance regression in the C++ query cpp/leap-year/unchecked-after-arithmetic-year-modification by restructuring the query’s dataflow computations to drastically reduce the number of sources/sinks (and resulting PathNodes) considered during evaluation.
Changes:
- Introduces an initial “pre-filter” dataflow (
OperationToYearAssignmentConfig0/OperationToYearAssignmentFlow0) to identify only operation-source candidates that can reach a year assignment. - Restricts the sinks of
IgnorableOperationToOperationSourceCandidateConfigto only those operation-source candidates that are relevant to year assignments. - Refactors the final
OperationToYearAssignmentConfigto use the restricted set and apply the ignorable-operation filtering in a later stage.
Show a summary per file
| File | Description |
|---|---|
| cpp/ql/src/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModification.ql | Reorders and splits dataflow configurations to constrain sink/source sets and improve evaluation performance. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 1
|
|
||
| /** | ||
| * The set of all expressions which is a candidate expression and also does not flow from to to some ignorable expression (eg. bitwise op) | ||
| * The set of all expressions which is a candidate expression. |
There was a problem hiding this comment.
The doc comment for OperationSource is grammatically incorrect/unclear (“The set of all expressions which is a candidate expression.”). Consider rephrasing to a plural form (for example, “The set of all expressions that are operation source candidates.”) so it reads cleanly and matches what the class represents.
Suggested change
| * The set of all expressions which is a candidate expression. | |
| * The set of all expressions that are operation source candidates. |
Contributor
There was a problem hiding this comment.
Suggested change
| * The set of all expressions which is a candidate expression. | |
| * The set of all expressions that are candidate expression. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a performance problem in cpp/leap-year/unchecked-after-arithmetic-year-modification which was caused by #21292.
The problem can be seen in this partial run:
The underlying problem is that the dataflow computation specified by
IgnorableOperationToOperationSourceCandidateConfighas way too many sources and sinks. So even though it is restricted to flows where the source and the sink are in the same enclosing callable there is way too manyPathNodes.To fix this problem we modify the ordering of dataflows. On
mainwe do (ignoring some of the other dataflow configurations used in this query):IgnorableOperationToOperationSourceCandidateConfigto identify operations to ignoreOperationSource, which then serve as the sources for the "final" dataflow computation specified byOperationToYearAssignmentConfig.After this PR we do:
OperationToYearAssignmentConfig0(which is equal to the originalOperationToYearAssignmentConfig, but without the filtering done byIgnorableOperationToOperationSourceCandidateConfig)IgnorableOperationToOperationSourceCandidateConfig. This is the same computation as we do onmain, but now restricted to only relevant sinks (which we get from (1))OperationToYearAssignmentConfig(which is equal toOperationToYearAssignmentConfig0, but with the restricted set of sinks from (2))On the particular database I was testing on this now completes "trivially" (since sentinals now detect that the query will have 0 results since
UncheckedLeapYearAfterYearModification::OperationToYearAssignmentFlow::Flow::S6::flowPath/2#9b05e974/2is empty).