Commit 8ba2dbe
committed
⚡ perf(link): skip fragment regex when fragment marker absent
Every `Link` runs `_egg_fragment_re.search` and `_subdirectory_fragment_re.search`
against `self._url` to find the matching fragment, even though Warehouse-served
URLs (the bulk of links a Simple-API response carries) never include either
fragment. Each regex search compiles a Boyer-Moore state and walks the full URL,
which adds up across the ~65000 links a moderately sized cross-platform lock
iterates per resolver pass.
Guard each search with a literal `"egg=" not in self._url` (resp. `"subdirectory="
not in self._url`) pre-check. Python's substring search is C-implemented and
runs an order of magnitude faster than the regex when the marker is absent;
when the marker is present the existing regex still runs, so behaviour is
preserved for VCS / direct-URL / `find-links` style URLs that carry it.
A new `test_fragments_absent_for_typical_links` parametrize asserts both
accessors return `None` for a representative spread of Simple-API URLs. The
existing `test_fragments` and `test_invalid_egg_fragments` cases all carry
explicit `#egg=…` / `&subdirectory=…` fragments and continue to exercise the
slow path.1 parent f7bfe28 commit 8ba2dbe
3 files changed
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
475 | 475 | | |
476 | 476 | | |
477 | 477 | | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
478 | 483 | | |
479 | 484 | | |
480 | 485 | | |
| |||
491 | 496 | | |
492 | 497 | | |
493 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
494 | 502 | | |
495 | 503 | | |
496 | 504 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
84 | 111 | | |
85 | 112 | | |
86 | 113 | | |
| |||
0 commit comments