RustPython / RustPython/Parser

Consider using `Box` on type parameters to reduce statement allocation size

未關閉
#94 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
Rust
星號
117
分支
38
平均合併
4 天 7 小時
30 天內合併 PR
1

描述

In https://github.com/RustPython/Parser/pull/93, we add type_params: Vec to ClassDef and FunctionDef which increases the size of a statement. We may want to optimize this field to reduce the size of the statement struct.

The main reason for the assertion is to be aware of how changing the AST changes its size. This is important because ruff and RustPython hold many instances of these types and increasing their size mean:

  • Each element in a Vec now requires more storage -> Overall increased memory consumption
  • Reading or writing an element becomes slower because your computer must read or write more bytes. This is especially relevant for reading where the L1 cache short circuits reads by caching about 64 bytes of neighboring memory to avoid subsequent reads from (the very slow) memory.

There's not much we can do about this here. This could be a place where using tinyvec over a regular Vec would be beneficial, considering that the vec will be empty for almost all instances. But I think this is fine for now.

Originally posted by @MichaReiser in https://github.com/RustPython/Parser/pull/93#discussion_r1259220991

貢獻指南

這個儲存庫沒有索引到貢獻指南

從這裡開始

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

研究方向

首先檢視 PR #93 以及 ClassDef 和 FunctionDef 的 AST 定義,重點關注新增的 type_params 欄位和討論中描述的陳述式大小斷言。比較目前 Vec 與提議的 Box 方案對配置的影響,同時考慮提到的 tinyvec 替代方案;當所選表示能夠減少不必要的陳述式大小且不破壞 AST 時,工作就完成了。

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

評估

技術堆疊
rust
領域
compilers
Issue 類型
重構
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
需要釐清
新手友好度
35/100

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

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