Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Nov 9, 2025

In Lexer::read_next_token, reaching EOF is very uncommon (because it only happens once at end of the file). Inform compiler of this using a #[cold] function, so it makes "not at EOF" the default path.

Small improvement on all the lexer and parser benchmarks (+1% on most lexer benchmarks).

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

overlookmotel commented Nov 9, 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 Nov 9, 2025

CodSpeed Performance Report

Merging #15512 will not alter performance

Comparing 11-09-perf_lexer_hint_to_compiler_that_eof_only_happens_once (bef04c1) with main (31718a8)

Summary

✅ 37 untouched

@overlookmotel overlookmotel marked this pull request as ready for review November 9, 2025 12:01
Copilot AI review requested due to automatic review settings November 9, 2025 12:01
@overlookmotel overlookmotel self-assigned this Nov 9, 2025
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 applies a performance optimization to the lexer's EOF handling by using a #[cold] attribute to hint to the compiler that the EOF branch is rarely taken, potentially improving branch prediction for the hot path.

  • Wraps the EOF return in a #[cold] function to optimize branch prediction

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

@overlookmotel overlookmotel requested a review from Boshen November 9, 2025 12:04
@overlookmotel overlookmotel assigned Boshen and unassigned overlookmotel Nov 9, 2025
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Nov 9, 2025
Copy link
Member

Boshen commented Nov 9, 2025

Merge activity

In `Lexer::read_next_token`, reaching EOF is very uncommon (because it only happens once at end of the file). Inform compiler of this using a `#[cold]` function, so it makes "not at EOF" the default path.

Small improvement on all the lexer and parser benchmarks (+1% on most lexer benchmarks).
@graphite-app graphite-app bot force-pushed the 11-09-perf_lexer_hint_to_compiler_that_eof_only_happens_once branch from bef04c1 to 2f0518d Compare November 9, 2025 12:40
@graphite-app graphite-app bot merged commit 2f0518d into main Nov 9, 2025
21 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 9, 2025
@graphite-app graphite-app bot deleted the 11-09-perf_lexer_hint_to_compiler_that_eof_only_happens_once branch November 9, 2025 12:46
Copilot AI pushed a commit that referenced this pull request Nov 9, 2025
In `Lexer::read_next_token`, reaching EOF is very uncommon (because it only happens once at end of the file). Inform compiler of this using a `#[cold]` function, so it makes "not at EOF" the default path.

Small improvement on all the lexer and parser benchmarks (+1% on most lexer benchmarks).
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