Skip to content

perf: Remove python coroutine/trampoline overhead in awaits for ~22% faster dependencies goal#23268

Merged
tobni merged 8 commits intopantsbuild:mainfrom
tobni:add/remove-python-trampoline-overhead
Apr 28, 2026
Merged

perf: Remove python coroutine/trampoline overhead in awaits for ~22% faster dependencies goal#23268
tobni merged 8 commits intopantsbuild:mainfrom
tobni:add/remove-python-trampoline-overhead

Conversation

@tobni
Copy link
Copy Markdown
Contributor

@tobni tobni commented Apr 16, 2026

 ➜  ✗ hyperfine --warmup 1 --command-name 'branch' 'PYENV_VERSION=pants@3.14.3                                     
  PANTS_SOURCE=<redacted>/code/pants pants --no-pantsd dependencies ::' --command-name 'main' 'PYENV_VERSION=pants@3.14.3 PANTS_SOURCE=/tmp/pants-main pants --no-pantsd dependencies ::'    
  Benchmark 1: branch                                                                                                                                                                          
    Time (mean ± σ):     25.094 s ±  0.306 s    [User: 30.610 s, System: 8.516 s]                                                                                                              
    Range (min … max):   24.775 s … 25.564 s    10 runs                                                                                                                                        
                                                                                                                                                                                               
  Benchmark 2: main                                                                                                                                                                            
    Time (mean ± σ):     32.304 s ±  0.183 s    [User: 37.097 s, System: 11.844 s]                                                                                                             
    Range (min … max):   32.008 s … 32.614 s    10 runs                                                                                                                                        
                                                                                                                                                                                               
  Summary                                                                                                                                                                                      
    branch ran                                                                                                                                                                                 
      1.29 ± 0.02 times faster than main                                                                                                                                                       

The numbers are measured targeting my company repo.

The improvements scales with the number of rule calls of a goal, as it it pure "per-call" python overhead that is eliminated.

Edit:
I purposefully have changed the typing to signal that the engine selectors aren't coroutines. I lived with the belief they were and that it was important. They were only coroutines because of wrappers, and nothing used the fact (anymore).

@tobni tobni added category:internal CI, fixes for not-yet-released features, etc. category:performance release-notes:not-required [CI] PR doesn't require mention in release notes labels Apr 16, 2026
@tobni tobni force-pushed the add/remove-python-trampoline-overhead branch from d44bec6 to 42a091a Compare April 16, 2026 23:35
@cburroughs
Copy link
Copy Markdown
Contributor

🤩 I'm just going to note here that _rule_call_trampoline is ~20% of Python on-cpu time in #23236, #18911, and my internal pants check case I mentioned on the last Developer Meeting.

And correctly propagate outputs
@tobni tobni force-pushed the add/remove-python-trampoline-overhead branch from 2f770a0 to 4937324 Compare April 17, 2026 10:26
@tobni tobni force-pushed the add/remove-python-trampoline-overhead branch from a1d0193 to 4dc0d52 Compare April 17, 2026 10:51
@tobni tobni changed the title pref: Remove python coroutine/trampoline overhead in awaits for ~22% faster dependencies goal perf: Remove python coroutine/trampoline overhead in awaits for ~22% faster dependencies goal Apr 17, 2026
@tobni tobni requested a review from benjyw April 17, 2026 18:35
@tobni tobni force-pushed the add/remove-python-trampoline-overhead branch from 3284a8d to 4de3ef3 Compare April 18, 2026 11:25
Previous method of "re-generatoring" was a hack
@tobni tobni force-pushed the add/remove-python-trampoline-overhead branch 3 times, most recently from c8f8d11 to bd98683 Compare April 18, 2026 17:01
Makes _Concurrently and Call have the same shape
@tobni tobni force-pushed the add/remove-python-trampoline-overhead branch from bd98683 to 735751e Compare April 18, 2026 20:09
Copy link
Copy Markdown
Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

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

Tricky to review, but I had looked at this code a few months back for the call-by-name work, so I think this is sound. And if any part of it was not, we'd have seen that in CI.

@benjyw
Copy link
Copy Markdown
Contributor

benjyw commented Apr 28, 2026

Excellent perf gain!

@tobni tobni merged commit 44ef956 into pantsbuild:main Apr 28, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:internal CI, fixes for not-yet-released features, etc. category:performance release-notes:not-required [CI] PR doesn't require mention in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants