Uh oh!
There was an error while loading. Please reload this page.
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`
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…_n6W-.rst Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…_n6W-.rst Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…eed_up_async_schedule
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
picnixz
left a comment
There was a problem hiding this comment.
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).
bdraco
commented
Aug 12, 2024
It works out to a
|
Added the number for the TimerHandle improvement. |
bdraco
commented
Aug 12, 2024
Thanks! |
itamaro
commented
Aug 12, 2024
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 |
bdraco
commented
Aug 24, 2024
@hauntsaninja I pushed the commit I had original held off on a5b6647 but than I realized you deleted your comment |
Uh oh!
There was an error while loading. Please reload this page.
hauntsaninja
commented
Aug 24, 2024
Ah, I deleted my comment because only the |
bdraco
commented
Aug 24, 2024
The |
mdboom
commented
Aug 29, 2024
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. |
bdraco
commented
Aug 29, 2024
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 |
bdraco
commented
Aug 29, 2024
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 |
1st1
left a comment
There was a problem hiding this comment.
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.
willingc
commented
Sep 10, 2024
Can you link to the issues re: aiohttp? |
willingc
left a comment
There was a problem hiding this comment.
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 |
willingc
commented
Sep 12, 2024
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(). |
bdraco
commented
Sep 18, 2024
Is this what you are looking for? |
itamaro
commented
Sep 19, 2024
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. |
1st1
commented
Sep 23, 2024
Yeah, basically what I expected. I think let's close it, unless the author comes up with a more significant and provable optimization. |
bdraco
commented
Sep 23, 2024
I did link to a benchmark with If the instagram server isn't doing a lot of |
Wrap the
TimerHandlein a tuple with thewhenvalue at the front to avoid having to callTimerHandle.__lt__forheapqoperations.