helpers: title() and description() are quadratic through smartquotes
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 65/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
- Domain
- backend, performance
Research direction
Read the title() and description() paths in @metascraper/helpers and inspect where titleize calls the third-party smartquotes rule. Compare outputs against smartquotes on a corpus, following test/equivalence.js; then add a timing test in packages/metascraper-helpers/test/linear-time.js. Done means both functions handle 100k-character quote-heavy input in a few milliseconds with the same output.
Written by the indexing model from the issue text.
Description
What happens
title() and description() in @metascraper/helpers (5.58.11, master 5b0dbfeb; unchanged by #907) take time quadratic in the length of their input when it alternates quotes and letters. Both call titleize, which runs smartquotes. smartquotes has a rule (\B|^)‘(?=([^‘’]*’\b)*…), and its lookahead rescans the rest of the string from every candidate quote.
This is a different cause from #905 (REGEX_LOCATION on a whitespace run).
Reproduce
const { title, description } = require('@metascraper/helpers')
const time = (name, fn) => { const t = performance.now(); fn(); console.log(name, (performance.now() - t).toFixed(0) + 'ms') }
for (const n of [25000, 50000, 100000]) {
time(`title "a' ${n}`, () => title('"a\''.repeat(n / 3)))
time(`description "a' ${n}`, () => description('"a\''.repeat(n / 3)))
time(`title a 'b ${n}`, () => title("a 'b".repeat(n / 4)))
}
Measured locally (Node 26, M-series laptop):
| input | 25k | 50k | 100k |
|---|---|---|---|
title('"a\''.repeat(n / 3)) |
83 ms | 327 ms | 1,330 ms |
description('"a\''.repeat(n / 3)) |
84 ms | 335 ms | 1,328 ms |
title("a 'b".repeat(n / 4)) |
62 ms | 243 ms | 1,016 ms |
On master, title('"a\''.repeat(33334)) takes 1,351 ms. A separate review measured over 30 s at 1M characters.
Expected
Linear time and the same output. smartquotes is third-party, so either replace the rule with a linear pass in helpers (and check equivalence against smartquotes on a corpus, as test/equivalence.js does for the URL regex), or fix it upstream.
Who gets it
Anyone who runs metascraper on HTML they do not control: every title and description rule passes the page's value through titleize.
Done when
title() and description() on a 100k-character quote-heavy input each finish in a few milliseconds, with a timing test in packages/metascraper-helpers/test/linear-time.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 52/100
microlinkhq/metascraper#906 ·
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