Skip to content

perf(lexer): tighten search loops#11118

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-18-perf_lexer_tighten_search_loops
May 18, 2025
Merged

perf(lexer): tighten search loops#11118
graphite-app[bot] merged 1 commit intomainfrom
05-18-perf_lexer_tighten_search_loops

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented May 18, 2025

Use slice iterators in the tight search loops in byte_search! macro.

This shaves off 2 instructions from each turn of the loop, and makes "no match" the default path on each iteration, which is better as search spends most of its time running through bytes that don't match, until it find one that does.

https://godbolt.org/z/99zo8esf8

+2% on one of lexer benchmarks.

It turns out idiomatic Rust is faster than C-style pointer manipulation! Who'd have thought it?

@github-actions github-actions bot added A-parser Area - Parser C-performance Category - Solution not expected to change functional behavior, only performance labels May 18, 2025
Copy link
Member Author

overlookmotel commented May 18, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented May 18, 2025

CodSpeed Instrumentation Performance Report

Merging #11118 will improve performances by 11.94%

Comparing 05-18-perf_lexer_tighten_search_loops (0f9b43e) with main (f1c221f)

Summary

⚡ 1 improvements
✅ 37 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
mangler[cal.com.tsx] 3.4 ms 3.1 ms +11.94%

@overlookmotel overlookmotel marked this pull request as ready for review May 18, 2025 13:59
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 18, 2025
Copy link
Member

Boshen commented May 18, 2025

Merge activity

Use slice iterators in the tight search loops in `byte_search!` macro.

This shaves off 2 instructions from each turn of the loop, and makes "no match" the default path on each iteration, which is better as search spends most of its time running through bytes that *don't* match, until it find one that does.

https://godbolt.org/z/99zo8esf8

+2% on one of lexer benchmarks.

It turns out idiomatic Rust is faster than C-style pointer manipulation! Who'd have thought it?
@graphite-app graphite-app bot force-pushed the 05-18-perf_lexer_use_offset_from_and_offset_from_unsigned_for_pointer_comparisons branch from 57f28e4 to 261e78b Compare May 18, 2025 15:59
@graphite-app graphite-app bot force-pushed the 05-18-perf_lexer_tighten_search_loops branch from 04c1fed to 0f9b43e Compare May 18, 2025 16:00
Base automatically changed from 05-18-perf_lexer_use_offset_from_and_offset_from_unsigned_for_pointer_comparisons to main May 18, 2025 16:06
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 18, 2025
@graphite-app graphite-app bot merged commit 0f9b43e into main May 18, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 05-18-perf_lexer_tighten_search_loops branch May 18, 2025 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants