Skip to content

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Sep 29, 2025

Split the error handling path from the hot path in expect() and expect_without_advance() functions to improve branch prediction. The CPU can now better predict the common success path.

Changes:

  • Add #[cold] #[inline(never)] handle_expect_failure() for error handling
  • Refactor expect() to inline success path and separate error path
  • Add #[inline] to expect_without_advance() for consistency
  • Maintain same behavior while improving performance

This addresses the high branch misprediction shown by callgrind profiling.

🤖 Generated with Claude Code

Split the error handling path from the hot path in expect() and expect_without_advance() functions to improve branch prediction. The CPU can now better predict the common success path.

Changes:
- Add #[cold] #[inline(never)] handle_expect_failure() for error handling
- Refactor expect() to inline success path and separate error path
- Add #[inline] to expect_without_advance() for consistency
- Maintain same behavior while improving performance

This addresses the high branch misprediction shown by callgrind profiling.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 29, 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.

@github-actions github-actions bot added A-parser Area - Parser C-performance Category - Solution not expected to change functional behavior, only performance labels Sep 29, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 29, 2025

CodSpeed Instrumentation Performance Report

Merging #14242 will not alter performance

Comparing optimize-expect (430bbaa) with main (a7e8662)

Summary

✅ 37 untouched

@Boshen Boshen marked this pull request as ready for review September 29, 2025 15:57
Copilot AI review requested due to automatic review settings September 29, 2025 15:57
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

Optimize the expect() and expect_without_advance() functions to reduce branch misprediction by separating the hot path (success case) from the cold path (error handling).

  • Extract error handling into a separate #[cold] #[inline(never)] function
  • Inline the success path in both expect() and expect_without_advance()
  • Add appropriate inlining attributes for performance optimization

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Boshen Boshen merged commit e6118fa into main Sep 29, 2025
28 checks passed
@Boshen Boshen deleted the optimize-expect branch September 29, 2025 15:59
@Boshen Boshen mentioned this pull request Oct 6, 2025
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