Optimize pathlib.PurePath.relative_to walk up case
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Feature or enhancement
Proposal:
pathlib.PurePath.relative_to method has a loop, which builds parents through every iteration of the loop. This makes it slow if we end up looping more than once. We could improve performance by caching the parents when looping multiple times.
The difficult part is how to make the changes so that they do not slow down two special cases:
- path == self
- we loop exactly once
So far all my attempts to improve this either slow down one or both of the above cases, which is why I have not yet done a PR. But if we could figure out ways to not slow down the above two, then the savings would be significant.
The best I have been able to come up with (I can make a PR if this looks good enough):
No changes if path == self
break on 1st loop, walk_up=False: 1.01x slower
1 level up: 1.09x slower
2 levels up: 1.25x faster
3 levels up: 1.46x faster
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
pathlib.PurePath.relative_to から始めて、親をたどる処理がどのように構築されているかを調べます。path == self、1 レベル、2 レベル、3 レベルの上方向への走査のケースでベンチマークを実施します; 完了条件は、2 つの特殊ケースを遅くせずに複数レベルの走査を改善することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- operating-systems
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100