Skip to content

perf(text): scan long textproto literals with memchr - #795

Open
fallintoplace wants to merge 1 commit into
anthropics:mainfrom
fallintoplace:perf/textproto-lex-long-literal-20261021-a
Open

fallintoplace wants to merge 1 commit into
anthropics:mainfrom
fallintoplace:perf/textproto-lex-long-literal-20261021-a

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

What

Scan long textproto string literals with memchr3.

Why

lex_string_run checks each byte in long unescaped strings.

Implementation

  • Search for quote, backslash, and newline in one call.
  • Keep the byte loop for short strings and after a special byte.
  • Keep memchr optional and preserve no_std support.

Benchmark

Tokenizer microbenchmark on Apple M1 Pro, Rust 1.95 release. Exact upstream base versus this branch, seven alternating runs; median ns/op. Lower is better.

Input Before After Speedup
Plain ASCII, 16 B 34.121 ns 35.270 ns 0.97x
Plain ASCII, 64 B 71.436 ns 28.868 ns 2.47x
Plain ASCII, 2 KiB 1,584.087 ns 118.391 ns 13.38x
Plain ASCII, 16 KiB 12,387.722 ns 771.388 ns 16.06x
UTF-8, about 2 KiB 1,593.851 ns 117.812 ns 13.53x
One escape, 2 KiB 1,587.509 ns 987.433 ns 1.61x
Dense escapes, 2 KiB 697.039 ns 806.209 ns 0.86x
Two adjacent literals, 2 KiB 1,592.575 ns 122.178 ns 13.03x

The 16 B case is about 3% slower and dense escapes about 14% slower in this run. Large plain literals are much faster. Benchmark harness.

@github-actions

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

This branch has not been deployed

No deployments
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