python / python/cpython

Optimize robotparser for long list of rules

未關閉
#149,381 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

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

描述

Previously, robotparser implemented old pre-standard specification which nobody uses now. It returned the result after finding the first matching rule, which worked incorrectly in many cases (see #83368). After #138907 it follows the longest path rule.

The code can be optimized, for example by sorting rules by the path length, matching them from longest to shorter and stopping if the match is longer than the remaining paths. This can only be used for paths which do not contain metacharacters * and $.

Other optimizations can also be used, for example a trie-like structure, which could also be used for paths with metacharacters. But this will significantly complicate the code.

I am not actually sure that such optimization is necessary. In most cases the number of rules should not be too large. This is why I did not include it in the previous PR. We need to collect some data first. So I publish my code as a draft.

Linked PRs
  • gh-149382

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

首先檢視 robotparser 的規則比對實作,以及以 gh-149382 連結的草稿工作。在選擇排序規則或類似 trie 的結構之前,收集規則清單大小與比對效能的資料;完成的條件是有證據顯示確實需要最佳化,且最長路徑行為仍然正確。

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

評估

技術堆疊
python
領域
networking
Issue 類型
重構
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

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

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