Skip to content

Optimize memchr with NEON - #161387

Closed
ywxt wants to merge 1 commit into
rust-lang:mainfrom
ywxt:memchr-aarch64-simd
Closed

ywxt wants to merge 1 commit into
rust-lang:mainfrom
ywxt:memchr-aarch64-simd

Conversation

@ywxt

@ywxt ywxt commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Result:

1. memchr:

Benchmark Length Before (ns/iter) After (ns/iter) Speedup (x)
fwd_match_first 16 3.80 3.45 1.10
  32 3.79 3.45 1.10
  64 3.79 3.80 1.0
  256 3.80 3.80 1.0
  1k 3.80 3.80 1.0
  4k 3.79 3.80 1.0
  64k 3.79 3.80 1.0
fwd_match_last 16 9.66 9.32 1.04
  32 10.01 9.66 1.04
  64 12.65 11.41 1.11
  256 28.74 14.15 2.03
  1k 89.09 31.60 2.82
  4k 336.51 90.49 3.72
  64k 5098.57 1761.04 2.90
fwd_match_none 16 3.45 3.11 1.11
  32 4.17 3.45 1.21
  64 6.25 3.45 1.81
  256 21.11 6.56 3.22
  1k 81.11 27.22 2.98
  4k 321.08 92.32 3.48
  64k 5107.51 1389.31 3.68
rev_match_first 16 10.39 8.06 1.29
  32 12.42 8.51 1.46
  64 16.67 10.92 1.53
  256 30.79 13.06 2.36
  1k 93.71 31.24 3.00
  4k 350.16 85.71 4.09
  64k 5364.25 1638.84 3.27
rev_match_last 16 4.36 2.11 2.07
  32 4.35 2.11 2.06
  64 4.30 3.14 1.37
  256 4.34 3.12 1.39
  1k 4.29 3.13 1.37
  4k 4.30 3.12 1.38
  64k 4.29 3.34 1.28
rev_match_none 16 4.23 2.21 1.91
  32 6.79 2.25 3.02
  64 7.78 2.87 2.71
  256 23.83 6.99 3.41
  1k 86.16 23.19 3.72
  4k 346.42 83.58 4.14
  64k 5368.44 1704.41 3.15

2 pattern

Benchmark Before (ns/iter) After (ns/iter) Speedup (x)
find_1byte_str_long_match_end 5180.74 1182.60 4.38
rfind_char_long_nomatch 5351.41 1279.11 4.18
rfind_1byte_str_long_nomatch 5391.75 1302.14 4.14
find_char_long_match_end 5096.61 1242.24 4.10
find_1byte_str_long_nomatch 5172.59 1286.60 4.02
find_char_long_nomatch 5104.69 1318.24 3.87
split_char_sparse 14326.42 4654.07 3.08
split_1byte_str_sparse 16889.26 7111.13 2.37
split_char_multibyte_haystack 69253.86 62913.94 1.10
split_1byte_str_multibyte_haystack 80609.83 78901.17 1.02
find_str_worst_case 1482.15 1460.42 1.01
split_char_dense 42748.78 43158.21 0.99
find_str 7090.74 7093.10 1.00
find_char_early_return 7787.22 7784.51 1.00
starts_with_str 4597.53 4599.39 1.00
starts_with_char 4598.04 4598.76 1.00
ends_with_str 4598.14 4599.04 1.00
ends_with_char 4597.97 4600.08 1.00
find_1byte_str_short_haystack 9242.62 9314.57 0.99
split_1byte_str_dense 54059.19 55237.39 0.98
find_1byte_str_early_return 11512.55 12162.06 0.95
find_char_short_haystack 5313.39 5569.64 0.95
rfind_str_worst_case 23512.81 24622.20 0.95
rfind_str 5708.62 6225.30 0.92

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 20, 2026
@rustbot

rustbot commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

r? @LawnGnome

rustbot has assigned @LawnGnome.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, LawnGnome, Mark-Simulacrum, clarfonthey, nia-e

@rust-log-analyzer

This comment has been minimized.

@ywxt
ywxt force-pushed the memchr-aarch64-simd branch from 2ab2c99 to 875501b Compare August 20, 2026 08:35
@ywxt

ywxt commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

r? @Amanieu

@rustbot rustbot assigned Amanieu and unassigned LawnGnome Aug 25, 2026
@Amanieu

Amanieu commented Aug 27, 2026

Copy link
Copy Markdown
Member

I don't think that doing something neon-specific here is the right approach. Instead we should consider importing the implementation from the memchr crate directly into the standard library.

See the discussion in #159090.

cc @BurntSushi @joboet

@ywxt ywxt closed this Sep 14, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants