Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve performance of C queries related to identifiers#242

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lcartey merged 4 commits intomainfromlcartey/improve-identifier-performance
Mar 29, 2023

Conversation

@lcartey
Copy link
Contributor

@lcarteylcartey commentedMar 8, 2023
edited by mbaluda
Loading

Description

This addresses performance issues raised by our performance testing on two rules from MISRA C 2012.

Rule 5.8

Per the commit message:

 The performance fix is to:     (a) Create a predicate which represents all the conflicting identifiers         by simply counting the number of declarations and confirming at         least one such declaration is external.     (b) Use this to create a result table of Declarations that conflict         with those identifiers.     (c) Implement a "non unique" external identifier class that provides a         member predicate to get all the conflicting declarations.        The key point here is to prevent the optimiser from doing a join between    Declaration.getName() and Declaration.getName(). Instead, the join is    between the names of the non-unique external identifiers and the much    smaller table of declarations that conflict with at least one such    entry

Rule 8.7

Per the commit message:

    Performance is improved with the following changes:     (a) Factoring out a predicate for the repeated calls to getTarget(), to         avoid duplication and to create a semantically meaningful predicate         which gets the target for a reference to an external identifier.     (b) Use the factored out predicate to refine the reference class to         only be references to external identifiers. This reduces the size         of the class.     (c) Create a predicate for computing a table of external identifiers,         references to those identifiers and the translation units those         exist in. We can then compute this table once, and use it in both         the "find me a reference to this external identifier" case and in         the "where the external identifier is not referenced in any other         translation unit" case.        Part (c) is the critical change. Without that, the optimizer was    creating an expensive join order in the negation case, where it    was effectively creating a cross product of all references to each    external identifier, before later excluding on the negation. The use    of our predicate in the negation case means we can first create a table    of external identifiers and translation units, then apply that in the    negation case without cross producting the references.

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 5.8
    • Rule 8.7

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 ofshared 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 thestyle 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 thestyle 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 rule was highlighted as performing poorly as it created aneffective cross product on declarations with the same name, which isexpensive on some databases.The performance fix is to: (a) Create a predicate which represents all the conflicting identifiers     by simply counting the number of declarations and confirming at     least on such declaration is external. (b) Use this to create a result table of Declarations that conflict     with those identifiers. (c) Implement a "non unique" external identifier class that provides a     member predicate to get all the conflicting declarations.The key point here is to prevent the optimiser from doing a join betweenDeclaration.getName() and Declaration.getName(). Instead, the join isbetween the names of the non-unique external identifiers and the muchsmaller table of declarations that conflict with at least one suchentry.
This rule was identified as containing one of the slowest predicates inour C Coding Standards query suites, and this commit improves theperformance.Performance is improved with the following changes: (a) Factoring out a predicate for the repeated calls to getTarget(), to     avoid duplication and to create a semantically meaningful predicate     which gets the target for a reference to an external identifier. (b) Use the factored out predicate to refine the reference class to     only be references to external identifiers. This reduces the size     of the class. (c) Create a predicate for computing a table of external identifiers,     references to those identifiers and the translation units those     exist in. We can then compute this table once, and use it in both     the "find me a reference to this external identifier" case and in     the "where the external identifier is not referenced in any other     translation unit" case.Part (c) is the critical change. Without that, the optimizer wascreating an expensive join order in the negation case, where itwas effectively creating a cross product of all references to eachexternal identifier, before later excluding on the negation. The useof our predicate in the negation case means we can first create a tableof external identifiers and translation units, then apply that in thenegation case without cross producting the references.
@github-actions
Copy link

🤖 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

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

COMPILE_ERROR_OUTPUT : QUERY                : IdentifiersWithExternalLinkageNotUniquePACKAGE              : Declarations6TEST_PASS            : TrueRULE                 : RULE-5-8COMPILE_PASS         : TrueTEST_DIFFERENCE      : SUITE                : MISRA-C-2012COMPILE_ERROR_OUTPUT : QUERY                : ShouldNotBeDefinedWithExternalLinkagePACKAGE              : Declarations6TEST_PASS            : TrueRULE                 : RULE-8-7COMPILE_PASS         : TrueTEST_DIFFERENCE      : SUITE                : MISRA-C-2012

@jsinglet
Copy link
Contributor

🤖 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

🤖 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

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

COMPILE_PASS         : TrueRULE                 : RULE-5-8TEST_DIFFERENCE      : QUERY                : IdentifiersWithExternalLinkageNotUniqueSUITE                : MISRA-C-2012PACKAGE              : Declarations6TEST_PASS            : TrueCOMPILE_ERROR_OUTPUT : COMPILE_PASS         : TrueRULE                 : RULE-8-7TEST_DIFFERENCE      : QUERY                : ShouldNotBeDefinedWithExternalLinkageSUITE                : MISRA-C-2012PACKAGE              : Declarations6TEST_PASS            : TrueCOMPILE_ERROR_OUTPUT :

@jsinglet
Copy link
Contributor

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

@github-actions
Copy link

🤖 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

🤖 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

🤖 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

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

SUITE                : MISRA-C-2012PACKAGE              : Declarations6RULE                 : RULE-5-8TEST_PASS            : TrueTEST_DIFFERENCE      : COMPILE_PASS         : TrueCOMPILE_ERROR_OUTPUT : QUERY                : IdentifiersWithExternalLinkageNotUniqueSUITE                : MISRA-C-2012PACKAGE              : Declarations6RULE                 : RULE-8-7TEST_PASS            : TrueTEST_DIFFERENCE      : COMPILE_PASS         : TrueCOMPILE_ERROR_OUTPUT : QUERY                : ShouldNotBeDefinedWithExternalLinkage

@jsinglet
Copy link
Contributor

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

PACKAGE              : Declarations6COMPILE_PASS         : TrueCOMPILE_ERROR_OUTPUT : RULE                 : RULE-5-8SUITE                : MISRA-C-2012QUERY                : IdentifiersWithExternalLinkageNotUniqueTEST_PASS            : TrueTEST_DIFFERENCE      : PACKAGE              : Declarations6COMPILE_PASS         : TrueCOMPILE_ERROR_OUTPUT : RULE                 : RULE-8-7SUITE                : MISRA-C-2012QUERY                : ShouldNotBeDefinedWithExternalLinkageTEST_PASS            : TrueTEST_DIFFERENCE      :

@jsinglet
Copy link
Contributor

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

@knewbury01knewbury01 self-requested a reviewMarch 13, 2023 15:53
Copy link
Contributor

@mbaludambaluda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM and TIL!

@lcarteylcartey added this pull request to themerge queueMar 29, 2023
@github-merge-queuegithub-merge-queuebot removed this pull request from themerge queue due to no response for status checksMar 29, 2023
@lcarteylcartey added this pull request to themerge queueMar 29, 2023
Merged via the queue intomain with commitd3d017bMar 29, 2023
@lcarteylcartey deleted the lcartey/improve-identifier-performance branchMarch 29, 2023 22:32
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mbaludambaludambaluda approved these changes

@knewbury01knewbury01Awaiting requested review from knewbury01

Assignees

No one assigned

Labels

None yet

Projects

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@lcartey@jsinglet@mbaluda

[8]ページ先頭

©2009-2025 Movatter.jp