python / python/cpython

Specialized `match_keys` for exact dictionary type

未關閉
#93,714 9 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

3.13 interpreter-core performance type-feature
主要語言
Python
星號
77.2k
分支
36k
平均合併
1 天 9 小時
30 天內合併 PR
558

描述

Feature or enhancement

I think it's probably worthwhile to write a specialized version of match_keys (for structural pattern matching of mappings) for exact dictionary types

Pitch

The most common mapping type is almost certainly the built-in dict. The match_keys function in ceval.c could be specialized to handle this type. Doing so would allow you to skip the dummy object, and replace the get call with PyDict_GetItemWithError. I don't think this should change the observable behaviour at all for exact dict

I'm in the process of reimplementing structural pattern matching on Cython, and this change gives ~2x optimization of some microbenchmarks.

If this change is deemed desirable I'm happy to implement it myself.

Previous discussion

Not aware of any

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從 ceval.c 中的 match_keys 開始,檢查 structural pattern matching 目前如何處理 mapping 鍵和精確的 dict 型別。當精確的 dict 使用專用路徑,同時不改變可觀察行為(包括現有的查找語義)時,修改就完成了;如果有可用的相關微基準,請進行比較。

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

評估

技術堆疊
c, python
領域
compilers
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
42/100

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

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