Skip to content

Skip RBS rewrite for files without RBS comments#2612

Draft
mattkubej wants to merge 1 commit intomainfrom
optimize-rbs-rewriter-prefilter
Draft

Skip RBS rewrite for files without RBS comments#2612
mattkubej wants to merge 1 commit intomainfrom
optimize-rbs-rewriter-prefilter

Conversation

@mattkubej
Copy link
Copy Markdown

What

Skip RBS source rewriting for typed Ruby files that do not contain RBS comment markers.

Tapioca's RBS rewriter currently calls Spoom::Sorbet::Translate.rbs_comments_to_sorbet_sigs for every file with a # typed: sigil. This adds a cheap prefilter so translation only runs when the source also contains #: or #|, the markers used by RBS comments.

Why

The RBS rewriter runs while application files are being loaded. In large applications, many typed files do not contain RBS comments, so calling the translator for each of them is unnecessary work.

This keeps the existing behavior for files that can contain RBS comments while avoiding translation attempts for files that cannot produce RBS-derived runtime signatures.

Safety

This should be behavior-preserving:

  • Files with # typed: and RBS comment markers still go through the existing translator.
  • Files without RBS comment markers have no RBS comments for the translator to rewrite.
  • False positives are acceptable because they preserve the old path for that file.

This does not change the broader Bootsnap/source-transform behavior; it only avoids unnecessary translator calls after source has been read.

Validation

Ran:

bundle exec ruby -I spec spec/tapioca/rbs/rewriter_spec.rb
bundle exec rubocop lib/tapioca/rbs/rewriter.rb spec/tapioca/rbs/rewriter_spec.rb

Both passed locally.

Follow-up

This is a conservative first step. A larger optimization would be to avoid disabling/bypassing Bootsnap for files that do not require RBS rewriting, while preserving byte-identical generated RBI output.

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.

1 participant