Skip to content

perf(semantic): avoid bounds check when checking string literal#17545

Merged
graphite-app[bot] merged 1 commit into
mainfrom
c/12-31-perf_semantic_test2
Jan 1, 2026
Merged

perf(semantic): avoid bounds check when checking string literal#17545
graphite-app[bot] merged 1 commit into
mainfrom
c/12-31-perf_semantic_test2

Conversation

@camc314

@camc314 camc314 commented Dec 31, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions github-actions Bot added A-semantic Area - Semantic C-performance Category - Solution not expected to change functional behavior, only performance labels Dec 31, 2025

camc314 commented Dec 31, 2025

Copy link
Copy Markdown
Contributor Author

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.

Base automatically changed from 12-31-perf_semantic_experiment to main December 31, 2025 21:31
@codspeed-hq

codspeed-hq Bot commented Dec 31, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #17545 will not alter performance

Comparing c/12-31-perf_semantic_test2 (79cce19) with main (04809d1)

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.

@camc314
camc314 marked this pull request as ready for review December 31, 2025 21:39
@camc314
camc314 requested a review from Dunqing as a code owner December 31, 2025 21:39
Copilot AI review requested due to automatic review settings December 31, 2025 21:39
@camc314
camc314 marked this pull request as draft December 31, 2025 21:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 string literal checking code by eliminating an Option wrapper in the hot path when searching for escape sequences. The optimization uses unsafe with proper safety guarantees.

Key changes:

  • Introduced a haystack that excludes the last byte (closing quote) to ensure any backslash found has a following byte
  • Replaced .get() with unsafe { get_unchecked() } for performance, eliminating the Option wrapper
  • Added debug_assert! and SAFETY comments to document the invariant

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

@camc314
camc314 force-pushed the c/12-31-perf_semantic_test2 branch from 149b228 to 79cce19 Compare December 31, 2025 21:42

@camchenry camchenry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks safe enough, and a +1% improvement on the jsx benchmark

@camc314 camc314 changed the title perf(semantic): test2 perf(semantic): avoid bounds check when checking string literal Jan 1, 2026
@camc314
camc314 marked this pull request as ready for review January 1, 2026 10:43
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Jan 1, 2026

camc314 commented Jan 1, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

@graphite-app
graphite-app Bot force-pushed the c/12-31-perf_semantic_test2 branch from 79cce19 to a28ab3d Compare January 1, 2026 15:25
@graphite-app
graphite-app Bot merged commit a28ab3d into main Jan 1, 2026
20 checks passed
@graphite-app
graphite-app Bot deleted the c/12-31-perf_semantic_test2 branch January 1, 2026 15:31
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jan 1, 2026
graphite-app Bot pushed a commit that referenced this pull request Jan 5, 2026
### 🚀 Features

- 659c23e linter: Init note field boilerplate  (#17589) (Shrey Sudhir)
- 6870b64 parser: Add TS1363 error code (#17609) (Sysix)
- 23680a3 mangler: Skip mangling only in scopes affected by direct eval (#17612) (camc314)
- a7e1643 parser: Add TS2528 error code to duplicate_default_export diagnostic (#17558) (camc314)

### 🐛 Bug Fixes

- 1044116 ecmascript: Mark `new Symbol` as non side-effect free (#17568) (camc314)
- ab5e4ca isolated-declarations: Strip default values from rest parameter binding patterns (#17602) (camc314)
- 68b2e54 minifier: Prevent incorrect ??= transformation when member base is mutated (#17472) (copilot-swe-agent)

### ⚡ Performance

- 6067143 semantic: Remove hash when checking identifier (#17564) (camchenry)
- a28ab3d semantic: Avoid bounds check when checking string literal (#17545) (camc314)
- 04809d1 semantic: Use SIMD for finding backslashes in `check_string_literal` (#17534) (camchenry)
- 49ad2f0 semantic: Mark all diagnostic functions as `#[cold]` (#17487) (camc314)
- ea82b50 transformer: Mark all diagnostic functions as `#[cold]` (#17486) (camc314)
- d968e51 semantic: Mark `checker::check` as `inline(always)` (#17459) (camc314)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-semantic Area - Semantic 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.

4 participants