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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize sqlparse.utils.imt(). #766

Merged
merged 1 commit into from
Mar 17, 2024

Conversation

adamchainz
Copy link
Contributor

Thanks for contributing!

Before submitting your pull request please have a look at the
following checklist:

  • ran the tests (pytest)
  • all style issues addressed (flake8)
  • your changes are covered by tests
  • your changes are documented, if needed

Profiling a sqlparse.parse() on a bunch of large SELECT queries, 14ms out of 59ms, or ~24% of the time, was spent in sqlparse.utils.imt().

Looking at that function, it did some moving of the m and t parameters into lists, wasting work when they’re not set or a single element which can use a faster check. To mitigate this, I optimized it to do the check only when the parameters are set, and avoid the listification of single elements.

This doubled its speed, saving 7ms in the same profile.

Copy link

codecov bot commented Mar 9, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 96.92%. Comparing base (60486b9) to head (e7eab4c).

Files Patch % Lines
sqlparse/utils.py 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #766      +/-   ##
==========================================
- Coverage   97.04%   96.92%   -0.12%     
==========================================
  Files          20       20              
  Lines        1558     1563       +5     
==========================================
+ Hits         1512     1515       +3     
- Misses         46       48       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andialbrecht
Copy link
Owner

Thanks for the patch! That makes the code much more readable as well.

@andialbrecht andialbrecht merged commit 012c9f1 into andialbrecht:master Mar 17, 2024
12 of 14 checks passed
@andialbrecht andialbrecht added this to the 0.5.0 milestone Mar 17, 2024
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.

2 participants