Skip to content

Compile literal binary patterns in the loader - #11468

Open
josevalim wants to merge 2 commits into
erlang:masterfrom
josevalim:jv-loader-optimizations
Open

Compile literal binary patterns in the loader#11468
josevalim wants to merge 2 commits into
erlang:masterfrom
josevalim:jv-loader-optimizations

Conversation

@josevalim

Copy link
Copy Markdown
Contributor

As we improve performance of binary:match/2,
compiling the pattern ends-up taking a higher cost of the
overall operation, so we automatically handle them in
the loader.

PS: I am not familiar with the loader and I cannot really assess
the quality of this patch but hopefully it is good enough to
start the conversation. @sverker has proposed a similar patch
for re:import/1 in the past.

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

CT Test Results

     5 files     545 suites   2h 3m 10s ⏱️
 4 553 tests  4 440 ✅ 113 💤 0 ❌
10 507 runs  10 369 ✅ 138 💤 0 ❌

Results for commit 2ba5a31.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

Allow non-empty lists of inclusive byte-range tuples
in binary:compile_pattern/1 and the binary match, matches,
split, and replace operations. Normalize overlapping
ranges and compile them to the new br pattern type.

Use SIMD for up to 16 normalized entries, with equality
checks for singletons and one-sided comparisons for ranges
touching 0 or 255. Use the 256-byte membership table for
tails, unsupported SIMD targets, and larger range sets.

ASCII validation throughput on arm64 macOS (million calls/s):

                       SIMD   Unicode   SWAR   Guard
    Valid ASCII       14.40      2.74   2.74    0.41
    Invalid last      13.78      3.00   2.74    0.41
    Invalid first     42.30    148.81  91.83  104.38

SIMD is the one added by this pull request, Unicode stands
for the current unicode:bin_is_7bit/1. Guard is the equivalent
guard imlpementation and the SWAR one is an optimized version
of that. The native unicode:bin_is_7bit/1 can be removed in
a future commit.

As shown in the benchmarks above, the new byte ranges are
clear winners for validating data, as most times you are
expecting to fully traverse binaries without matches.
For parsing, byte ranges can be faster than guards, but may
be beaten by SWAR on certain payloads.
@jhogberg jhogberg added the team:VM Assigned to OTP team VM label Aug 17, 2026
@jhogberg jhogberg self-assigned this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants