Skip to content

Speed-up cache lookup through Python C-API - #121

Merged
bdraco merged 19 commits into
aio-libs:masterfrom
Vizonex:0.3.3-Optimizations
Jun 10, 2025
Merged

bdraco merged 19 commits into
aio-libs:masterfrom
Vizonex:0.3.3-Optimizations

Conversation

@Vizonex

@Vizonex Vizonex commented Jun 10, 2025 •

Copy link
Copy Markdown
Member

What do these changes do?

These Changes optimize cache behavior by using CPython's API Calls Directly which can enhance the performance of the code significantly.

Are there changes in behavior for the user?

Nope. Just internal-refactoring.

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

@codspeed

codspeed Bot commented Jun 10, 2025 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #121 will improve performances by 13.86%

Comparing Vizonex:0.3.3-Optimizations (4bd7f09) with master (dea0355)

Summary

⚡ 2 improvements
✅ 2 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
⚡ test_cached_property_cache_miss 149.5 µs 131.7 µs +13.56%
⚡ test_under_cached_property_cache_miss 149.5 µs 131.3 µs +13.86%

@codecov

codecov Bot commented Jun 10, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.76%. Comparing base (dea0355) to head (4bd7f09).
⚠️ Report is 19 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #121   +/-   ##
=======================================
  Coverage   97.76%   97.76%           
=======================================
  Files          17       17           
  Lines         760      760           
  Branches       41       41           
=======================================
  Hits          743      743           
  Misses          9        9           
  Partials        8        8           
Flag Coverage Δ
CI-GHA 97.76% <ø> (ø)
MyPy 93.30% <ø> (ø)
OS-Linux 96.91% <ø> (ø)
OS-Windows 93.27% <ø> (ø)
OS-macOS 93.27% <ø> (ø)
Py-3.10.11 91.03% <ø> (ø)
Py-3.10.17 93.27% <ø> (ø)
Py-3.10.18 ?
Py-3.11.12 95.23% <ø> (ø)
Py-3.11.9 92.99% <ø> (ø)
Py-3.12.10 92.99% <ø> (-2.25%) ⬇️
Py-3.12.11 94.95% <ø> (?)
Py-3.13.3 95.23% <ø> (ø)
Py-3.13.4t 95.23% <ø> (ø)
Py-3.9.13 91.01% <ø> (ø)
Py-3.9.22 91.01% <ø> (-2.25%) ⬇️
Py-3.9.23 92.97% <ø> (ø)
Py-pypy7.3.16 92.97% <ø> (ø)
Py-pypy7.3.19 92.99% <ø> (ø)
VM-macos-latest 93.27% <ø> (ø)
VM-ubuntu-latest 96.91% <ø> (ø)
VM-windows-latest 93.27% <ø> (ø)
pytest 96.91% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Vizonex

Vizonex commented Jun 10, 2025

Copy link
Copy Markdown
Member Author

CodSpeed Performance Report

Merging #121 will improve performances by 15.54%

Comparing Vizonex:0.3.3-Optimizations (fb99eb7) with master (dea0355)

Summary

⚡ 2 improvements ✅ 2 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
⚡ test_cached_property_cache_miss 149.3 µs 129.2 µs +15.54%
⚡ test_under_cached_property_cache_miss 150.1 µs 132.5 µs +13.24%

Whelp isn't that just wonderful. I thought it would be a lot smaller than that.

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Jun 10, 2025
@Vizonex

Vizonex commented Jun 10, 2025

Copy link
Copy Markdown
Member Author

yay it worked :)

@bdraco

bdraco commented Jun 10, 2025 •

Copy link
Copy Markdown
Member
[towncrier-fragments]:10: : Spell check: api: Optimized propcache by replacing sentient object for checking if the object is null and changed dictionary api for C Python api. -- by .
[towncrier-fragments]:10: : Spell check: api: Optimized propcache by replacing sentient object for checking if the object is null and changed dictionary api for C Python api. -- by .
Writing /home/runner/work/propcache/propcache/docs/_build/spelling/changes.spelling
writing output... [ 60%] contributing/guidelines
writing output... [ 80%] contributing/release_guide
writing output... [100%] index
WARNING: Found 2 misspelled words

If you replace it with API it should work

Comment thread CHANGES/121.feature.rst Resolved
@webknjaz webknjaz changed the title Small Performance Tweaks Speed-up cache lookup through Python C-API Jun 10, 2025
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
@Vizonex

Vizonex commented Jun 10, 2025

Copy link
Copy Markdown
Member Author

Fixed 👍

@Vizonex

Vizonex commented Jun 10, 2025

Copy link
Copy Markdown
Member Author

I was going to bring this up as a comment in the code but I chose not to but the reason I chose PyObject_CallOneArg was to have a faster call since there's only one argument being used and 3.9 was when it came out and it's the final version as of currently that is not EOL.

Comment thread src/propcache/_helpers_c.pyx Resolved
Comment thread src/propcache/_helpers_c.pyx Resolved
Comment thread src/propcache/_helpers_c.pyx Resolved
@Vizonex

Vizonex commented Jun 10, 2025

Copy link
Copy Markdown
Member Author

Fixed reference counting.

@Vizonex

Vizonex commented Jun 10, 2025

Copy link
Copy Markdown
Member Author

I wonder why the documentation generator is failing 😕

Comment thread CHANGES/121.feature.rst Resolved
@bdraco

bdraco commented Jun 10, 2025 •

Copy link
Copy Markdown
Member

Comment thread src/propcache/_helpers_c.pyx Resolved
@bdraco

bdraco commented Jun 10, 2025

Copy link
Copy Markdown
Member

Thanks @Vizonex

@bdraco

bdraco commented Jun 10, 2025 •

Copy link
Copy Markdown
Member

If you still want to look for improvement and come up with a way to improve the test_under_cached_property_cache_hit case as well in a future PR, thats the true bottleneck for aiohttp and yarl

@Vizonex

Vizonex commented Jun 10, 2025

Copy link
Copy Markdown
Member Author

If you still want to look for improvement and come up with a way to improve the test_under_cached_property_cache_hit case as well in a future PR, thats the true bottleneck for aiohttp and yarl

I probably will look into yarl a bit later. I actually am going to have a lot of time on my hands this summer to do so.

Comment thread src/propcache/_helpers_c.pyx Resolved
@bdraco
bdraco enabled auto-merge (squash) June 10, 2025 16:07
@bdraco
bdraco merged commit 4c645c7 into aio-libs:master Jun 10, 2025
@Vizonex
Vizonex deleted the 0.3.3-Optimizations branch June 15, 2025 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants