Skip to content

Hoist entity name regexp in Text.check - #391

Merged
naitoh merged 1 commit into
ruby:masterfrom
g4lb:perf-text-check-entity-name-regexp
Nov 29, 2026
Merged

naitoh merged 1 commit into
ruby:masterfrom
g4lb:perf-text-check-entity-name-regexp

Conversation

@g4lb

@g4lb g4lb commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Text.check compiled the regexp /\A#{Entity::NAME}\z/um for each named entity reference. Now the regexp is a constant. The regexp is the same, so the output does not change.

Input Ruby 4.0 4.0 + YJIT Ruby 2.6 JRuby 10.1
Text with predefined entities -86% -89% -77% -64%
Attribute values with entities -74% -82% -58% -47%

Documents without named entity references do not use the changed line. I measured no slowdown on them. I used 20 interleaved rounds and a Mann-Whitney test (Apple M5).

Checks:

  • ruby test/run.rb passes on Ruby 2.6, Ruby 4.0 and JRuby.
  • Old and new outputs matched on 1,000,000 random documents.

@naitoh naitoh 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.

+1

@naitoh
naitoh merged commit 121633d into ruby:master Nov 29, 2026
71 checks passed
@naitoh

naitoh commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

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.

2 participants