helpers: getUrls() is quadratic in the length of one word
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
- Domain
- backend, performance
Research direction
Start by reading getUrls() in @metascraper/helpers and the URL regex, then inspect test/equivalence.js for the compatibility corpus. Compare how candidate start positions are handled and run the reproducer with increasingly long words. Done means a 100k-character word completes in a few milliseconds while returning the same matches as the equivalence corpus.
Written by the indexing model from the issue text.
Description
What happens
After #904's fix, getUrls() in @metascraper/helpers is no longer exponential, but it is still quadratic in the length of one whitespace-free word. The URL regex is unanchored in match mode. At every start position inside a long run of host characters, the attempt reads to the end of the run before it fails.
Reproduce
const { getUrls } = require('@metascraper/helpers')
for (const n of [10000, 20000, 40000]) {
const t = performance.now()
getUrls('a'.repeat(n))
console.log(n, (performance.now() - t).toFixed(0) + 'ms')
}
With #904 applied (Node 26, M-series laptop): 10k 273 ms, 20k 1,101 ms, 40k 4,461 ms. On master a 5k word already takes 25 s.
Expected
Linear time with the same matches. re2 is linear, but it is not a drop-in replacement. It reads \s as ASCII only, [¡-] excludes astral characters, and its case folding maps ſ to s. So the fix has to keep JavaScript semantics, for example a scanner that skips start positions where no match can begin.
Who gets it
metascraper-x calls it on X post descriptions, which can be up to 25k characters.
Done when
getUrls() on a 100k-character word finishes in a few milliseconds and returns the same matches as today on the equivalence corpus in test/equivalence.js.
🤖 Generated with Claude Code
- Dominant language
- HTML
- Stars
- 2.8k
- Forks
- 183
- Avg merge
- 1h 16m
- Merged PRs (30d)
- 9
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microlinkhq/metascraper
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
microlinkhq/metascraper#905 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
microlinkhq/metascraper#903 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
microlinkhq/metascraper#901 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
microlinkhq/metascraper#909 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 65/100
microlinkhq/metascraper#908 ·
Maintainers usually reply within 1 day
All issues in microlinkhq/metascraper
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ranxianglei/billion-context#8319 ·
Maintainers usually reply within 1 day
-
backend bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
nolte/kamerplanter#3193 ·
Maintainers usually reply within 1 day
-
bug documentation queries
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ClickHouse/clickhouse-cs#815 ·
Maintainers usually reply within 1 day
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100