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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule 20.12: Improve performance #241

Merged
merged 2 commits into from
Mar 29, 2023
Merged

Rule 20.12: Improve performance #241

merged 2 commits into from
Mar 29, 2023

Conversation

lcartey
Copy link
Collaborator

@lcartey lcartey commented Mar 7, 2023

Description

This commit optimizes the from-where-select clause of this query, which was highlighted as one of the slowest predicates for our C query suites.

This commit makes the following changes:

  • Avoid repetition of m.getParameter(i), which caused a cross product
  • Change the way we identify "further expanded macro"
  • Modify the isExcluded predicate to reference the macro invocation not the macro.

@rvermeulen I think you wrote this rule originally, so I would appreciate a review. In particular, the change from

  exists(Macro furtherExpandedMacro |
    mi.getUnexpandedArgument(i).matches(furtherExpandedMacro.getName() + "%")
  )

to

not mi.getUnexpandedArgument(i) = mi.getExpandedArgument(i)

Achieves what you originally intended.

@mbaluda @jsinglet this addresses one of the slowest performing predicates that was highlighted in #226, although the slow performance is not related to the upgrade itself.

Change request type

  • Release or process automation (GitHub workflows, internal scripts)
  • Internal documentation
  • External documentation
  • Query files (.ql, .qll, .qls or unit tests)
  • External scripts (analysis report or other code shipped as part of a release)

Rules with added or modified queries

  • No rules added
  • Queries have been added for the following rules:
    • rule number here
  • Queries have been modified for the following rules:
    • Rule 20.12

Release change checklist

A change note (development_handbook.md#change-notes) is required for any pull request which modifies:

  • The structure or layout of the release artifacts.
  • The evaluation performance (memory, execution time) of an existing query.
  • The results of an existing query in any circumstance.

If you are only adding new rule queries, a change note is not required.

Author: Is a change note required?

  • Yes
  • No

馃毃馃毃馃毃
Reviewer: Confirm that format of shared queries (not the .qll file, the .ql file that imports it) is valid by running them within VS Code.

  • Confirmed

Reviewer: Confirm that either a change note is not required or the change note is required and has been added.

  • Confirmed

Query development review checklist

For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:

Author

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Reviewer

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

This commit optimizes the from-where-select clause of this query, which
was highlighted as one of the slowest predicates for our C query suites.

This commit makes the following changes:
 * Avoid repetition of `m.getParameter(i)`, which caused a cross product
 * Change the way we identify "further expanded macro"
 * Modify the isExcluded predicate to reference the macro invocation not
   the macro.
@lcartey lcartey requested a review from rvermeulen March 7, 2023 23:30
@github-actions
Copy link

github-actions bot commented Mar 7, 2023

馃 Beep Boop! Matrix Testing for this PR has been initiated. Please check back later for results.

馃挕 If you do not hear back from me please check my status! I will report even if this PR does not contain files eligible for matrix testing.

@jsinglet
Copy link
Contributor

jsinglet commented Mar 7, 2023

馃 Beep Boop! gcc/c/x86_64 Matrix Testing for this PR has been completed. See below for the results!


PACKAGE              : Preprocessor2
TEST_PASS            : True
SUITE                : MISRA-C-2012
COMPILE_ERROR_OUTPUT : 
QUERY                : MacroParameterUsedAsHashOperand
COMPILE_PASS         : True
TEST_DIFFERENCE      : 
RULE                 : RULE-20-12


@jsinglet
Copy link
Contributor

jsinglet commented Mar 7, 2023

馃 Beep Boop! clang/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test!

@jsinglet
Copy link
Contributor

jsinglet commented Mar 7, 2023

馃 Beep Boop! gcc/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test!

@jsinglet
Copy link
Contributor

jsinglet commented Mar 7, 2023

馃 Beep Boop! clang/c/x86_64 Matrix Testing for this PR has been completed. See below for the results!


TEST_DIFFERENCE      : 
QUERY                : MacroParameterUsedAsHashOperand
SUITE                : MISRA-C-2012
COMPILE_PASS         : True
TEST_PASS            : True
RULE                 : RULE-20-12
PACKAGE              : Preprocessor2
COMPILE_ERROR_OUTPUT : 


@jsinglet
Copy link
Contributor

jsinglet commented Mar 7, 2023

馃 Beep Boop! Matrix Testing for this PR has been completed. If no reports were posted it means this PR does not contain things that need matrix testing!

@lcartey
Copy link
Collaborator Author

lcartey commented Mar 8, 2023

Updated the issue body - I meant that the poor performance was not related to the upgrade!

@lcartey lcartey added this pull request to the merge queue Mar 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 29, 2023
@lcartey lcartey added this pull request to the merge queue Mar 29, 2023
Merged via the queue into main with commit 8dc1ea5 Mar 29, 2023
@lcartey lcartey deleted the lcartey/20-12-improve-perf branch March 29, 2023 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants