Skip to content

perf(mobile): compare terminal themes without serialization - #17455

Merged
nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/perf-mobile-terminal-theme-equality
Aug 31, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/perf-mobile-terminal-theme-equality

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

ELI5

Mobile repeatedly asks whether terminal themes changed. It used to turn both themes into JSON strings just to compare them. Themes are shallow color maps, so this compares their fields directly without creating strings.

What Changed

  • Add an allocation-free equality check for terminal mode and color fields.
  • Use it for session-tab and terminal-list reconciliation.
  • Compare all own enumerable color fields so a field added by a newer host still triggers an update.

Why

Terminal/session snapshots reconcile repeatedly. Serializing both theme objects on every unchanged comparison creates avoidable strings and scans the same data twice.

Performance Measurement

Deterministic repeated-comparison fixture:

  • Before: 2 JSON.stringify calls per theme comparison.
  • After: 0 JSON.stringify calls.
  • Improvement: 100% removal of measured theme serialization (4,000 serializations avoided across the test's 2,000 equality calls).

The regression test makes JSON.stringify throw and completes all comparisons, while separate coverage proves changed modes/colors and newer-host fields still compare correctly.

User-Facing Trade-offs

None. Equal themes remain equal; any known or future own color-field change still refreshes the terminal. No transport or persisted shape changes.

Linked Issue

N/A — proactive performance audit.

Visual Proof

N/A — terminal colors and update behavior are unchanged.

Testing

  • pnpm test src/session/mobile-terminal-records.test.ts (14 passed)
  • pnpm typecheck in mobile/
  • Focused mobile oxlint and format checks

Review

Self-reviewed for undefined themes, mode changes, field insertion order, additional fields from newer hosts, and remote wire compatibility.

Agent skill upstream boundary

  • Not applicable.

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 2 minutes.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 06736732-005e-4be2-b9aa-69bb9c4fda0f

📥 Commits

Reviewing files that changed from the base of the PR and between ba5f334 and 6ba8f8f.

📒 Files selected for processing (2)
  • mobile/src/session/mobile-terminal-records.test.ts
  • mobile/src/session/mobile-terminal-records.ts

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.

@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces JSON serialization-based terminal-theme equality checks with direct mode and own-color-field comparisons, avoiding repeated allocations during mobile session reconciliation.

  • Adds an allocation-free terminal-theme comparator that handles undefined themes, mode changes, and forward-compatible color fields.
  • Uses the comparator for session-tab and terminal-record equality.
  • Adds regression coverage for serialization avoidance and newer-host theme fields.

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness, compatibility, or security issues identified.

The new comparator preserves the relevant terminal-theme contract of mode plus string-valued color fields while correctly detecting added, removed, and changed own fields.

Important Files Changed

Filename Overview
mobile/src/session/mobile-terminal-records.ts Adds direct terminal-theme equality and integrates it into both reconciliation equality paths without an identified correctness regression.
mobile/src/session/mobile-terminal-records.test.ts Verifies comparisons avoid JSON serialization and detect additional host-provided color fields.

Reviews (1): Last reviewed commit: "perf(mobile): compare terminal themes wi..." | Re-trigger Greptile

@pullfrog pullfrog Bot 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.

ℹ️ No critical issues — one minor coverage suggestion below.

Reviewed changes

Adds an allocation-free equality check for mobile terminal themes (mode plus every own enumerable color field) and swaps out the two JSON.stringify comparisons in the session reconciliation path, with a serialization-guard regression test.

  • mobileTerminalThemesEqual — new helper comparing theme mode and all own enumerable color fields in both directions, with a left === right fast path and Object.hasOwn guards.
  • Call-site replacement — mobileSessionTabEqual (terminal case) and terminalRecordsEqual now compare themes directly instead of stringifying.
  • Tests — a JSON.stringify-spy regression test (throws if serialization happens) and a newer-host-extra-field test.

ℹ️ Nitpicks

  • The first loop's value-inequality branch (leftColors[color] !== rightColors[color]) is never exercised by any assertion: darkTheme vs lightTheme differs in mode (early return), equivalentTheme reorders identical keys, and withNewField adds a key on one side. A one-line same-key/different-color assertion would pin the comparison that actually detects a repainted color.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 7a72976 into stablyai:main Aug 31, 2026
23 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant