Skip to content

perf(intl): avoid parser offset scans#2161

Merged
innocenzi merged 1 commit into
tempestphp:3.xfrom
xHeaven:perf/intl-parser-linear-char-access
Jun 5, 2026
Merged

perf(intl): avoid parser offset scans#2161
innocenzi merged 1 commit into
tempestphp:3.xfrom
xHeaven:perf/intl-parser-linear-char-access

Conversation

@xHeaven
Copy link
Copy Markdown
Member

@xHeaven xHeaven commented Jun 5, 2026

The parser used mb_substr() every time it read the next character. With UTF-8 strings, mb_substr() has to scan from the start of the string to reach that character, so long translations got much slower than they should.
In my benchmark, these numbers showed up:

Characters Original New Speedup
2,000 4.568 ms 0.275 ms 16.6×
4,000 17.252 ms 0.545 ms 31.7×
8,000 62.975 ms 1.082 ms 58.2×
16,000 239.825 ms 2.141 ms 112.0×
32,000 936.264 ms 4.258 ms 219.9×

@innocenzi innocenzi merged commit 027a76f into tempestphp:3.x Jun 5, 2026
76 checks passed
@xHeaven xHeaven deleted the perf/intl-parser-linear-char-access branch June 5, 2026 23:40
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