python / python/cpython

Improve performance of `os.walk()`

未關閉
#119,169 3 則留言 3 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

performance
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

There are a couple of minor performance improvements possible in os.walk():

  • We don't need to manually pump the os.scandir iterator, given we handle exceptions from next() like exceptions from scandir() itself, i.e. by ignoring the problematic directory and moving on. We can use a for loop like filthy casuals.
  • In bottom-up mode, we can handle exceptions from entry.is_symlink() in the same block as those from entry.is_dir(), which avoids a few temporary variables.
  • In top-down mode, we can call os.path.join() once on a parent directory rather than for each child path.
Linked PRs
  • gh-119186
  • gh-119473
  • gh-119573
  • gh-119750
  • gh-121431
  • gh-121432
  • gh-121433
  • gh-121435

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從 os.walk() 入口點開始,檢查其對 os.scandir()、entry.is_dir()、entry.is_symlink() 和 os.path.join() 的使用。在進行變更之前,先檢閱相關的 PR:gh-119186、gh-119473、gh-119573、gh-119750、gh-121431、gh-121432、gh-121433 和 gh-121435;當所提議的效能改進保留例外處理和走訪行為時,即表示完成。

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

評估

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

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

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