Skip to content

Conversation

antonag32
Copy link
Contributor

Added simple profiling test cases to get insights into the program
flow and possible bottlenecks of the system. The profiling
can be done on user-repositories with the following command:

PROFILING_TEST_REPO=path/to/repo tox -e cprofile


  • Some XPath expressions were improved to offload work from python code

  • Similar to regex, xpath expressions are compiled at the class level and
    reused by checks, this means they are only compiled once instead of
    multiple times. More info:https://lxml.de/xpathxslt.html#the-xpath-class

  • There was a false negative in test_repo/broken_module/skip_xml_check2.xml:3,
    xml-data-deprecated-node should be raised but was not, this was discovered
    when improving the xpath expressions. Apparently the previous method
    (using iterchildren) also counted comments in.

Added simple profiling test cases to get insights into the program
flow and possible bottlenecks of the system. The profiling
can be done on user-repositories with the following command:

`PROFILING_TEST_REPO=path/to/repo tox -e cprofile`
@antonag32 antonag32 changed the title REF] improve XPath expressions, compile them only once, fix false negative [REF] improve XPath expressions, compile them only once, fix false negative Jun 26, 2023
@antonag32 antonag32 changed the title [REF] improve XPath expressions, compile them only once, fix false negative Draft: [REF] improve XPath expressions, compile them only once, fix false negative Jun 26, 2023
…gative

* Some XPath expressions were improved to offload work from python code

* Similar to regex, xpath expressions are compiled at the class level and
  reused by checks, this means they are only compiled once instead of
  multiple times. More info:https://lxml.de/xpathxslt.html#the-xpath-class

* There was a false negative in test_repo/broken_module/skip_xml_check2.xml:3,
  xml-data-deprecated-node should be raised but was not, this was discovered
  when improving the xpath expressions. Apparently the previous method
  (using iterchildren) also counted comments in.
@antonag32 antonag32 changed the title Draft: [REF] improve XPath expressions, compile them only once, fix false negative [REF] improve XPath expressions, compile them only once, fix false negative Jun 26, 2023
@antonag32
Copy link
Contributor Author

Initially I was just going to add cprofile tests to get a baseline idea of the state of the program. I don't think optimization is a priority right now but implementing the tests was simple and did not hurt.

I then found out XPath expressions could be compiled and used the approach out of curiosity to see if there were any perf improvements. My observations show a 5-10% improvement in program run time. During the POC I found out some xpath expressions could be improved to reduce the need for python processing and also fixed a false negative (I think) so I thought the changes were helpful enough to grant an MR.

Can you review @moylop260 @luisg123v

@moylop260
Copy link
Collaborator

Interesting PR

FYI I had created a similar PR for Pylint a long time ago, but it was not merged:

Thank you!

@luisg123v

Could you review it, please?

@luisg123v luisg123v self-requested a review June 27, 2023 01:57
@@ -11,6 +11,35 @@


class ChecksOdooModuleXML:
xpath_deprecated_data = etree.XPath("/odoo[count(./*) < 2]/data|/openerp[count(./*) < 2]/data")
xpath_view_replaces = etree.XPath(
".//field[@name='name' and @position='replace'][1] | .//*[@position='replace'][1]"

Choose a reason for hiding this comment

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

I think 1st term is redundant

@moylop260 moylop260 merged commit 1c1834d into OCA:main Jun 27, 2023
@moylop260 moylop260 deleted the profiler-anton branch June 27, 2023 16:33
@luisg123v
Copy link

@moylop260 It looks you didn't consider #78 as I commented on #78 (review)

@moylop260
Copy link
Collaborator

@moylop260 It looks you didn't consider #78 as I commented on #78 (review)

@antonag32 vas wey

antonag32 added a commit to vauxoo-dev/odoo-pre-commit-hooks that referenced this pull request Jun 27, 2023
Removed a redundant term in one of the xpath expressions and
refactored code from PR OCA#79 to reuse the same xpath expression.
moylop260 pushed a commit that referenced this pull request Jun 27, 2023
Removed a redundant term in one of the xpath expressions and
refactored code from PR #79 to reuse the same xpath expression.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants