Skip to content

Conversation

@camchenry
Copy link
Member

@camchenry camchenry commented Nov 26, 2025

One profile of the parser showed that this function took up 1% of the time on binder.ts. It seemed like this is a case where we could possibly remove the bounds checks, since our tokens are guaranteed to be contained within the source string. Since this is called really often, it's worth optimizing.

+1% on all parser benchmarks:

image

Copy link
Member Author

camchenry commented Nov 26, 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.

@camchenry camchenry changed the base branch from 11-25-feat_parser_add_diagnostic_for_jsx_identifiers_with_hyphens to graphite-base/16135 November 26, 2025 02:59
@camchenry camchenry force-pushed the 11-25-perf_parser_remove_bounds_check_for_getting_strings_from_lexer branch from 53034be to 9d60b34 Compare November 26, 2025 03:00
@camchenry camchenry force-pushed the 11-25-perf_parser_remove_bounds_check_for_getting_strings_from_lexer branch from 9d60b34 to 5c73320 Compare November 26, 2025 03:05
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 26, 2025

CodSpeed Performance Report

Merging #16135 will not alter performance

Comparing 11-25-perf_parser_remove_bounds_check_for_getting_strings_from_lexer (45740bd) with main (17a8caa)

Summary

✅ 42 untouched
⏩ 3 skipped1

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camchenry camchenry changed the base branch from graphite-base/16135 to main November 26, 2025 03:18
@camchenry camchenry marked this pull request as ready for review November 26, 2025 03:18
Copilot AI review requested due to automatic review settings November 26, 2025 03:18
Copilot finished reviewing on behalf of camchenry November 26, 2025 03:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the get_string method in the lexer by replacing safe string slicing operations with unsafe get_unchecked to eliminate bounds checking. The optimization targets a hot path that profiling showed took 1% of parsing time on binder.ts, achieving a +1% performance improvement across all parser benchmarks.

Key Changes:

  • Refactored string extraction to compute adjusted start/end positions before slicing
  • Replaced safe slice operations with unsafe { get_unchecked(start..end) }
  • Added comprehensive debug assertions to validate safety invariants

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@graphite-app graphite-app bot changed the base branch from main to graphite-base/16135 November 26, 2025 04:34
@graphite-app graphite-app bot force-pushed the 11-25-perf_parser_remove_bounds_check_for_getting_strings_from_lexer branch from 5c73320 to 099a5ce Compare November 26, 2025 04:39
@graphite-app graphite-app bot changed the base branch from graphite-base/16135 to main November 26, 2025 04:39
@graphite-app graphite-app bot force-pushed the 11-25-perf_parser_remove_bounds_check_for_getting_strings_from_lexer branch from 099a5ce to 811c1a4 Compare November 26, 2025 04:39
@graphite-app graphite-app bot changed the base branch from main to graphite-base/16135 November 26, 2025 09:23
@graphite-app graphite-app bot force-pushed the 11-25-perf_parser_remove_bounds_check_for_getting_strings_from_lexer branch from 811c1a4 to 1fca5af Compare November 26, 2025 09:28
@graphite-app graphite-app bot changed the base branch from graphite-base/16135 to main November 26, 2025 09:29
@graphite-app graphite-app bot force-pushed the 11-25-perf_parser_remove_bounds_check_for_getting_strings_from_lexer branch from 1fca5af to 45740bd Compare November 26, 2025 09:29
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.

3 participants