python / python/cpython

JIT doesn't trace exec()-generated functions called from hot loops

未關閉
#149,564 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

interpreter-core topic-JIT type-feature
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

When a hot loop calls functions generated via exec(), the loop body gets traced but the callees don't. Each callee is individually cold (called ~60 times), but the call site is hot (5,000+ calls total across different callees).

Concrete case: tinygrad generates ~5,000 pattern matching functions at startup via exec(). They're called from a tight loop:

for _, match, _ in pats:
    if (ret := match(uop, ctx)) is not None: return ret

PYTHON_JIT=1 on 3.14.4 produces no improvement. The specializer works (LOAD_ATTR_SLOT fires correctly), but the JIT never compiles the callees.

Related: faster-cpython/ideas#738, #118093 (tier 2 entry at function calls).

It would be useful to either trace through exec()-generated callees at hot call sites, or detect aggregate hotness across callees sharing a call site.

Linked PRs
  • gh-149575

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先,在 Python 3.14.4 上使用 PYTHON_JIT=1 重現 tinygrad 的模式匹配迴圈,重點關注由 exec() 產生的被呼叫方以及它們共用的熱門呼叫點。將 specializer 的 LOAD_ATTR_SLOT 行為與被呼叫方是否被編譯進行比較;當回報的熱門呼叫工作負載顯示透過產生的函式獲得了 JIT 改善時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
compilers, performance
Issue 類型
缺陷
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。