Skip to content

perf: replace 8 filter passes with single-pass message categorization#108

Merged
matt1398 merged 2 commits intomatt1398:mainfrom
MintCollector:fix/single-pass-message-filter
Mar 11, 2026
Merged

perf: replace 8 filter passes with single-pass message categorization#108
matt1398 merged 2 commits intomatt1398:mainfrom
MintCollector:fix/single-pass-message-filter

Conversation

@MintCollector
Copy link
Contributor

@MintCollector MintCollector commented Mar 10, 2026

Summary

  • Replaces 8 separate .filter() calls in SessionParser.processMessages() with a single for...of loop and switch statement
  • Uses else if for isParsedRealUserMessage / isParsedInternalUserMessage since they are mutually exclusive (checked by isMeta)
  • Reduces array iterations from 8× to 1× per session parse

Addresses #95

Test plan

  • All 653 tests pass
  • Typecheck clean
  • Lint clean
  • Production build succeeds
  • Verified realUser and internalUser are mutually exclusive via isMeta flag

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Optimized internal message processing efficiency in the session handler through streamlined classification operations.

MintCollector and others added 2 commits March 10, 2026 09:19
SessionParser.processMessages() was iterating 10K messages 8 times
(one per .filter() call). Replace with a single for-of loop that
categorizes each message into all applicable buckets in one pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
isParsedRealUserMessage and isParsedInternalUserMessage are mutually
exclusive, so the second check is unnecessary when the first is true.
Convert to if/else if to avoid the redundant evaluation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant performance enhancement to the message processing logic within the SessionParser. By consolidating multiple array filtering operations into a single iteration, it streamlines the categorization of messages, reducing redundant computations and improving overall efficiency. This change directly addresses a known performance bottleneck, making the session parsing process faster and more resource-friendly.

Highlights

  • Performance Optimization: Replaced 8 separate .filter() calls in SessionParser.processMessages() with a single for...of loop and switch statement for message categorization.
  • Conditional Logic: Implemented else if for isParsedRealUserMessage / isParsedInternalUserMessage checks, leveraging their mutual exclusivity.
  • Efficiency Improvement: Reduced array iterations from 8x to 1x per session parse, significantly improving processing efficiency.
Changelog
  • src/main/services/parsing/SessionParser.ts
    • Refactored message categorization from multiple filter calls to a single for...of loop with a switch statement.
    • Optimized realUser and internalUser message checks using else if conditions within the single loop.
    • Integrated sidechain and main message separation into the primary iteration, further reducing array traversals.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai coderabbitai bot added the feature request New feature or request label Mar 10, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is a great performance improvement, replacing 8 filter passes with a single loop. This significantly reduces the number of iterations over the messages array. I've left one suggestion for a minor additional optimization within the loop.

Comment on lines +101 to +105
if (isParsedRealUserMessage(m)) {
byType.realUser.push(m);
} else if (isParsedInternalUserMessage(m)) {
byType.internalUser.push(m);
}

Choose a reason for hiding this comment

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

medium

Since this PR is focused on performance, we can make a small additional optimization here.

Given that we are inside case 'user', isParsedInternalUserMessage(m) is equivalent to checking m.isMeta. Also, isParsedRealUserMessage(m) will only be true if !m.isMeta.

We can reorder the checks to be slightly more efficient by checking m.isMeta directly. This avoids one function call to isParsedRealUserMessage when m.isMeta is true, and replaces the call to isParsedInternalUserMessage with a direct property access.

Suggested change
if (isParsedRealUserMessage(m)) {
byType.realUser.push(m);
} else if (isParsedInternalUserMessage(m)) {
byType.internalUser.push(m);
}
if (m.isMeta) {
byType.internalUser.push(m);
} else if (isParsedRealUserMessage(m)) {
byType.realUser.push(m);
}

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a0e7e04f-1811-437a-8775-31a38f55634d

📥 Commits

Reviewing files that changed from the base of the PR and between f23c581 and 4092fa1.

📒 Files selected for processing (1)
  • src/main/services/parsing/SessionParser.ts

📝 Walkthrough

Walkthrough

Refactored processMessages in SessionParser.ts to classify messages using a single-pass loop with type-based categorization, replacing the previous eight separate filter passes while maintaining the same return structure.

Changes

Cohort / File(s) Summary
Message Processing Optimization
src/main/services/parsing/SessionParser.ts
Reworked processMessages to use iterative categorization via switch statement on message type instead of multiple filter passes. Consolidated population of byType categories (user, realUser, internalUser, assistant, system, other) and message separation (sidechainMessages, mainMessages) into single loop.

Suggested labels

feature request

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@matt1398 matt1398 merged commit 362c402 into matt1398:main Mar 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants