Skip to content

Load CGI once for HTML anchors, reduce build time by 23% - #1894

Open
skatkov wants to merge 1 commit into
ruby:masterfrom
skatkov:perf/load-cgi-once
Open

skatkov wants to merge 1 commit into
ruby:masterfrom
skatkov:perf/load-cgi-once

Conversation

@skatkov

@skatkov skatkov commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

RDoc::MethodAttr#html_name called require for every method and attribute anchor.

Change

Load the same CGI modules once, following the pattern already used in RDoc::Markup::ToHtml.

On Google API Ruby Client at 5eb8108, building Compute, Drive, and google-apis-core with Aliki took 32.73s → 25.13s (23% less wall time).

Both variants produced 3,286 HTML pages, and diff -qr -x created.rid found no differences between the generated sites.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Documentation preview

View the preview

Commit: acec66f

@skatkov
skatkov marked this pull request as ready for review December 1, 2026 16:57
Copilot AI balanced review requested due to automatic review settings December 1, 2026 16:57

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

No active review issues were identified for the change moving CGI dependency loading to file scope.

No open issues 🎉

What changed in this PR

This PR reduces repeated loading checks during RDoc HTML anchor generation by loading CGI dependencies when RDoc::MethodAttr is loaded.

Changes:

  • Moves CGI requires from html_name to file scope.
  • Preserves the conditional cgi/util fallback and leaves anchor escaping unchanged.
File Description
lib/​rdoc/​code_object/​method_attr.rb Loads CGI dependencies once rather than checking them for every method or attribute anchor.

Review effort: Balanced

@skatkov skatkov changed the title Load CGI once for HTML anchors Load CGI once for HTML anchors, reduce build time by 23% Dec 1, 2026
@skatkov

skatkov commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

CI failure is not related to these changes, please see #1896

st0012 pushed a commit that referenced this pull request Dec 5, 2026
Currently two of my PRs are affected by this issue, see #1894 and #1895.

The TruffleRuby job on macOS can fail if the preview server’s health
check runs before the server starts listening. TruffleRuby 40.0.0 can
return an unconnected socket instead of raising `ECONNREFUSED`, causing
`Net::HTTP` to raise `EINVAL` when it sets `TCP_NODELAY`. See
[TruffleRuby
#4510](truffleruby/truffleruby#4510).
Copilot AI balanced review requested due to automatic review settings December 5, 2026 16:38
@skatkov
skatkov force-pushed the perf/load-cgi-once branch from e895d6a to acec66f Compare December 5, 2026 16:38

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

No active review issues block approval of the change to load CGI once and reduce anchor-generation overhead.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants