Skip to content

Cache regexp in Markup::ToHtml - #1824

Open
Earlopain wants to merge 1 commit into
ruby:masterfrom
Earlopain:optimize-markup-to-html
Open

Earlopain wants to merge 1 commit into
ruby:masterfrom
Earlopain:optimize-markup-to-html

Conversation

@Earlopain

Copy link
Copy Markdown
Contributor

Especially the first one is not good for performance.

In ruby/prism, docs generation goes from 7s to 6.75s for me, which is about a 4% improvement (including bundler startup etc, so for pure rdoc timing it should be even better)

Especially the first one is not good for performance.

In ruby/prism, docs generation goes from 7s to 6.75s for me, which is about a 4%
improvement (including bundler startup etc, so for pure rdoc timing it should be even better)
Copilot AI balanced review requested due to automatic review settings September 17, 2026 20:05
@github-actions

Copy link
Copy Markdown

Documentation preview

View the preview

Commit: cbb8e36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused optimization preserves existing behavior covered by formatter tests.

Pull request overview

Caches reusable regular expressions in Markup::ToHtml, reducing formatter initialization overhead without changing matching behavior.

Changes:

  • Caches the HTML character alias regexp as a constant.
  • Uses /o to compile the interpolated hyperlink regexp once.
File summaries
File Description
lib/rdoc/markup/to_html.rb Reuses compiled regular expressions during formatter initialization.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@skatkov

skatkov commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

I already have benchmarks developed for my previous work - took this PR for a benchmark spin.

I could not reproduce improvements in Prism, but Rails docs generation definitely improved (not only in speed, but more notably in memory allocations)

Variant Total Time Peak RSS Live heap after generation
Baseline 22.83s 415.4 MiB 1,908,566
PR #1824 21.87s 375.2 MiB 1,838,027
Change -4.2% -9.7% -3.7%

It would be lovely if this PR could be merged.

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.

3 participants