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

Reduce notifications for a minor speedup #704

Merged
merged 9 commits into from
Dec 10, 2024
Merged

Conversation

x42005e1f
Copy link
Contributor

@x42005e1f x42005e1f commented Dec 6, 2024

Avoids calling slow notification methods when there are no waiters.

@x42005e1f
Copy link
Contributor Author

x42005e1f commented Dec 6, 2024

In fact, false positive cases (the number of waiters is higher than it actually is) are possible, since the thread must enter the finally block to decrement. But access to the waiting queue requires access to the undocumented Condition attribute (_waiters, both async and sync), which may break in future versions of Python or other implementations of the standard library, so it is not used in this PR. Also, due to the delayed effect of notifications (as they are performed via new tasks and threads), it is basically impossible to obtain actual information unless complex cancellation handling is added. Therefore, the number of notifications is not optimal, but still safe.

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 96.72131% with 4 lines in your changes missing coverage. Please review.

Project coverage is 94.42%. Comparing base (ad2b1bd) to head (7b404db).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
tests/test_mixed.py 93.65% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #704      +/-   ##
==========================================
- Coverage   94.44%   94.42%   -0.02%     
==========================================
  Files           5        5              
  Lines        1369     1472     +103     
  Branches      109      127      +18     
==========================================
+ Hits         1293     1390      +97     
- Misses         52       55       +3     
- Partials       24       27       +3     

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

Copy link

codspeed-hq bot commented Dec 6, 2024

CodSpeed Performance Report

Merging #704 will improve performances by 78.94%

Comparing x42005e1f:master (7b404db) with master (ad2b1bd)

Summary

⚡ 4 improvements

Benchmarks breakdown

Benchmark master x42005e1f:master Change
test_bench_async_put_sync_get 1,089.9 ms 125.9 ms ×8.7
test_bench_sync_put_async_get 1,150.2 ms 636.9 ms +80.59%
test_bench_sync_put_async_join 1,196.7 ms 255.8 ms ×4.7
test_sync_join_async_done 1,167.2 ms 652.3 ms +78.94%

@asvetlov
Copy link
Member

asvetlov commented Dec 6, 2024

Thanks, the speedup looks very impressive!
I'll take a careful review after sleeping on the PR.

@asvetlov
Copy link
Member

asvetlov commented Dec 8, 2024

@x42005e1f thank you for adding more tests! I'm out of my laptop right now, I'll review the PR again when I come back.

Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@asvetlov asvetlov merged commit 4a57895 into aio-libs:master Dec 10, 2024
13 checks passed
@x42005e1f x42005e1f mentioned this pull request Dec 11, 2024
asvetlov pushed a commit that referenced this pull request Dec 11, 2024
## What do these changes do?

This PR fixes hang in `AsyncQueue.join()` by replacing `asyncio.Event`
with `asyncio.Condition`. It also:

1. Makes the names of primitives the same style.
2. Reduces notifications in #704 style.
3. Ensures that counters are changed exclusively.

## Are there changes in behavior for the user?

There are no behavior changes for users.

## Related issue number

Fixes #715
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