Speed up array appends

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

維護者通常 2 天內回覆

@harshitgupta31415 已經在處理了。

開始於 2026年10月15日。

  • #666 來自 @harshitgupta31415 —— 未關閉

評估

難度
4/5
預估耗時
1-2 天
新手友好度
42/100
Issue 類型
重構
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
python
領域
data

研究方向

Start from the array append path that tomlkit.dumps reaches when a Python list is converted, and find where the index is rebuilt for every existing item. Time the 3000-item example before changing anything. Done means that a normal append only indexes the new item, middle inserts and special formatting items still rebuild, and the output text and existing tests stay the same.

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

描述

Adding an item to the end of an array rebuilds the index for every item already in it. So when an array is built one item at a time, the same entries get checked over and over.

This also happens when writing a Python list with tomlkit.dumps, not just when calling append directly. It can add up when writing a long file list or dependency list.

For example, this goes through the repeated append path:

import tomlkit

files = [f"src/package/module_{n}.py" for n in range(3000)]
text = tomlkit.dumps({"files": files})

For a normal append, the old items haven't moved. Could we keep their indexes and add only the new one? Middle inserts and the special formatting items can keep the current rebuild.

For N normal appends, that would bring the index work from O(N²) to O(N), without adding another cache. Converting the values and writing the TOML would still take their own time.

主要語言
Python
星號
864
分支
207
平均合併
3 天 23 小時
30 天內合併 PR
25

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

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

python-poetry/tomlkit 的其他 Issue

查看 python-poetry/tomlkit 的全部 Issue

相似的 Issue

更多 Python Issue

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

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