Repository navigation
gh-162282: Fix remaining quadratic paths in urllib.robotparser - #162442
Conversation
Merging many groups for the same user agent copied the accumulated rule lines on every merge, and _find_entry() checked a group once per user agent in it, so a single lookup for an unlisted agent was quadratic in the number of agents. Extend a merged entry in place when no other agent shares it, reuse one merged entry for all agents of a group that shared the same entry, and check each distinct entry only once in _find_entry(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3d419a5 to
056377c
Compare
|
Thanks @asvetlov for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15. |
|
GH-162449 is a backport of this pull request to the 3.15 branch. |
|
GH-162450 is a backport of this pull request to the 3.14 branch. |
…GH-162442) (#162450) gh-162282: Fix remaining quadratic paths in urllib.robotparser (GH-162442) Merging many groups for the same user agent copied the accumulated rule lines on every merge, and _find_entry() checked a group once per user agent in it, so a single lookup for an unlisted agent was quadratic in the number of agents. Extend a merged entry in place when no other agent shares it, reuse one merged entry for all agents of a group that shared the same entry, and check each distinct entry only once in _find_entry(). (cherry picked from commit 06eb745) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…GH-162442) (#162449) gh-162282: Fix remaining quadratic paths in urllib.robotparser (GH-162442) Merging many groups for the same user agent copied the accumulated rule lines on every merge, and _find_entry() checked a group once per user agent in it, so a single lookup for an unlisted agent was quadratic in the number of agents. Extend a merged entry in place when no other agent shares it, reuse one merged entry for all agents of a group that shared the same entry, and check each distinct entry only once in _find_entry(). (cherry picked from commit 06eb745) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
|
Follow-up to #162283. Two more input shapes were quadratic:
rulelines. A merged entry is now extended in place when no other agent shares it._find_entry()checked the same entry once per agent, so every lookup for an unlisted agent was quadratic. All agents of a group now share one merged entry, and each distinct entry is checked once.Results are unchanged: a differential fuzz against the previous version over 90,000 random robots.txt files found no differences. With 4000 agents (debug build),
can_fetch("unknownbot")drops from 10 s to 0.001 s.🤖 Generated with Claude Code