python / python/cpython

Improve performance of `os.walk()`

オープン
#119,169 コメント 3 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

performance
主要言語
Python
スター
77.2k
フォーク
36k
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. リポジトリをフォークし、ブランチを切って変更します。
  4. 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 を短くまとめたダイジェスト。