Skip to content

perf(lexer): use offset_from and offset_from_unsigned for pointer comparisons#11116

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

perf(lexer): use offset_from and offset_from_unsigned for pointer comparisons#11116
graphite-app[bot] merged 1 commit intomainfrom
05-18-perf_lexer_use_offset_from_and_offset_from_unsigned_for_pointer_comparisons

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented May 18, 2025

Lexer use offset_from and offset_from_unsigned pointer methods rather than comparing pointers as usizes.

This utilizes the PointerExt trait introduced in #11095. This change tells the compiler "both these pointers are into the same object, and origin pointer is before target pointer", which gives it more information for optimization, and alias analysis.

This change also allows simplifying Source a little - we now almost entirely now deal in SourcePositions, rather than a mix of SourcePositions, raw pointers, and ptr as usize.

Tiny improvement on lexer benchmarks. Interestingly, it seems to produce a consistent ~1% speed-up in the byte handler for /. It seems to particularly have a positive effect on lexing single-line comments, for some reason.

@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 #11116 will improve performances by 12.55%

Comparing 05-18-perf_lexer_use_offset_from_and_offset_from_unsigned_for_pointer_comparisons (261e78b) with main (f1c221f)

Summary

⚡ 1 improvements
✅ 37 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
mangler[cal.com.tsx] 3.4 ms 3 ms +12.55%

@overlookmotel overlookmotel marked this pull request as ready for review May 18, 2025 13:41
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label May 18, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented May 18, 2025

Merge activity

… comparisons (#11116)

Lexer use `offset_from` and `offset_from_unsigned` pointer methods rather than comparing pointers as `usize`s.

This utilizes the `PointerExt` trait introduced in #11095. This change tells the compiler "both these pointers are into the same object, and origin pointer is before target pointer", which gives it more information for optimization, and alias analysis.

This change also allows simplifying `Source` a little - we now almost entirely now deal in `SourcePosition`s, rather than a mix of `SourcePosition`s, raw pointers, and `ptr as usize`.

Tiny improvement on lexer benchmarks. Interestingly, it seems to produce a consistent ~1% speed-up in the byte handler for `/`. It seems to particularly have a positive effect on lexing single-line comments, for some reason.
@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 merged commit 261e78b into main May 18, 2025
24 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 18, 2025
@graphite-app graphite-app bot deleted the 05-18-perf_lexer_use_offset_from_and_offset_from_unsigned_for_pointer_comparisons branch May 18, 2025 16:06
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.

1 participant