-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
gh-122881: Reduce asyncio heapq scheduling overhead #122882
Conversation
Wrap the TimerHandle in tuples with the when value at the front to avoid having to call `TimerHandle.__lt__` when working with the `heapq`
Misc/NEWS.d/next/Library/2024-08-10-13-10-45.gh-issue-122881.z_n6W-.rst
Outdated
Show resolved
Hide resolved
…_n6W-.rst Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks.
Misc/NEWS.d/next/Library/2024-08-10-13-10-45.gh-issue-122881.z_n6W-.rst
Outdated
Show resolved
Hide resolved
…_n6W-.rst Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…eed_up_async_schedule
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have numbers, you could also add them to the NEWS entry, saying that you improved the performances by a factor X for instance, otherwise I'm good (still requires a core dev for the final acceptance).
It works out to a
|
Added the number for the TimerHandle improvement. |
Thanks! |
I have a few questions
|
This has already been discussed above. Is this strictly required?
I'm not sure the
The memory impact should be negligible compared to the cost of |
@hauntsaninja I pushed the commit I had original held off on a5b6647 but than I realized you deleted your comment |
Ah, I deleted my comment because only the |
The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
I ran this PR against the pyperformance suite on our benchmarking hardware. The results overall are basically "no change", within the noise. The vast majority of the benchmarks there don't use async, however, we do have the async benchmarks broken out separately, and even there the results are kind of inconclusive. The async benchmarks in pyperformance are actually known to have a great deal of inherent variability, so, honestly it's hard to conclude too much from them. Results on async benchmarks only
From these results, I'd say there's no obvious win or obvious red flag to merging this. The microbenchmark in #122881 shows a significant improvement, and if the additional code complexity is acceptable to others, this is probably fine to merge. |
I took a look at https://github.com/python/pyperformance/tree/main/pyperformance and I don't see any asyncio benchmarks that will generate a significant amount of |
For context, I've been working on addressing some performance complaints from aiohttp users. What finally pushed me to submit this upstream was how much more time is spent in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion these sort of micro-optimizations aren't worth it as they mostly just harm readability. The effect of this optimization will be barely detectable. If you want performance - use uvloop.
-1.
Can you link to the issues re: aiohttp? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see the aiohttp performance issues before I weigh in on the need for this change.
bdraco was analysing performance issues, but some of the discussion around that is in aio-libs/aiohttp#8608 and the thread: aio-libs/aiohttp#8608 (comment) I think one concern here is that .reschedule is a public, high-level API: https://docs.python.org/3/library/asyncio-task.html#asyncio.Timeout.reschedule |
Thanks @Dreamsorcerer for additional information. I'm at -0 in my view on this change at present. Personally, I would need to see more evidence of real world impact for me to support this optimization. I will remove the "Do Not Merge" label in case another core team member feels strongly to merge this. Thanks @bdraco for the PR too and the detailed explanations. |
#122881 (comment) microbenchmark doesn't use modified code: it doesn't use the asyncio event loop :-( It's a benchmark on Can you write a benchmark using the asyncio event loop? For example, schedule 1000 callbacks with call_at(). |
Is this what you are looking for? |
As a benchmarking data point - I applied a minimally modified version (ported to cinder 3.10) of this PR to Instagram Server, and there was no measurable perf impact. |
Yeah, basically what I expected. I think let's close it, unless the author comes up with a more significant and provable optimization. |
I did link to a benchmark with If the instagram server isn't doing a lot of |
Wrap the
TimerHandle
in a tuple with thewhen
value at the front to avoid having to callTimerHandle.__lt__
forheapq
operations.