Skip to content

fix: Improve the performance of the CONTENT_PATTERN regex in RSS parser to avoid backtracking issues.#67

Merged
kou merged 2 commits into
ruby:masterfrom
connorshea:content-pattern-perf
Jun 10, 2026
Merged

fix: Improve the performance of the CONTENT_PATTERN regex in RSS parser to avoid backtracking issues.#67
kou merged 2 commits into
ruby:masterfrom
connorshea:content-pattern-perf

Conversation

@connorshea

@connorshea connorshea commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

This improves the performance of the XML stylesheet parsing a good amount.

RSS::Parser.parse on <?xml-stylesheet aaaa…=?>, Ruby 3.4.9:

n (chars) before (HEAD) after (fix) speedup
10,000 0.131 s 0.0004 s ~330×
20,000 0.508 s 0.0003 s ~1,600×
40,000 1.966 s 0.0004 s ~5,000×
80,000 7.847 s 0.0007 s ~11,000×

Fixes #66.

…er to avoid backtracking issues.

This improves the performance of the XML stylesheet parsing a good amount.

`RSS::Parser.parse` on `<?xml-stylesheet aaaa…=?>`, Ruby 3.4.9:

| n (chars) | before (HEAD) | after (fix) | speedup |
|-----------|--------------:|------------:|--------:|
| 10,000 | 0.131 s | 0.0004 s | ~330× |
| 20,000 | 0.508 s | 0.0003 s | ~1,600× |
| 40,000 | 1.966 s | 0.0004 s | ~5,000× |
| 80,000 | 7.847 s | 0.0007 s | ~11,000× |
Comment thread lib/rss/parser.rb Outdated
@kou kou merged commit 4bef4c2 into ruby:master Jun 10, 2026
42 checks passed
@kou

kou commented Jun 10, 2026

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance issue in regex for XML stylesheet parsing

2 participants