Skip to content

[Perf-LH] Reuse renderer locale collators - #13444

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-lh-renderer-collators
Aug 10, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-lh-renderer-collators

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Summary

This PR makes seven renderer sort expressions reuse the expensive locale-collation setup they currently repeat for every comparison.

In plain language: several Orca lists need “human” ordering, such as putting TASK-2 before TASK-10 or comparing names without case/accent sensitivity. Today those call String.localeCompare with an options object from inside the sort callback. A sort invokes that callback roughly n log n times, and each option-bearing call resolves the same ICU collation configuration again.

The affected paths are:

  • browser palette ordering;
  • simulator palette ordering;
  • workspace-tab palette ordering;
  • Linear identifier ordering;
  • Jira key ordering;
  • native-chat discovered-skill ordering;
  • native-chat picker-skill ordering.

What changes

A small renderer module now owns two exact comparison modes:

Mode Existing semantics Reused semantics
Base sensitivity locale undefined, sensitivity: 'base' identical
Natural numeric locale undefined, numeric: true identical

Each comparator initializes its Intl.Collator only when that comparison mode is first used, then reuses it for every later comparison.

The lazy initialization is important. Constructing the first ICU collator can itself take several milliseconds in a fresh renderer process. Eager module-level construction would move that cost into module loading even when the user never opens one of these sorted surfaces. This implementation keeps the old “pay only on first use” behavior and removes only repeated setup.

The following intentionally remain unchanged:

  • locale stays undefined, so each platform keeps using the same runtime-default locale it used before;
  • the optionless skill-path localeCompare fallback still breaks equal-name ties;
  • Orca’s fileNameCollator is not reused because it pins locale to en and adds a code-unit tie-breaker;
  • the Jira-project collator is not reused because it combines numeric and base-sensitivity options, which would change these comparisons;
  • the app’s selectable UI language is not substituted for the JavaScript runtime locale.

Benchmark

Run:

node config/scripts/locale-collator-sort-benchmark.mjs

The committed harness:

  • uses deterministic shuffled inputs;
  • imports the real shared production comparator;
  • imports the real sortJiraIssues production function for the numeric arm;
  • compares every before/after sorted output before timing;
  • calibrates each arm to at least 120 ms per round;
  • alternates before/after measurement order to reduce CPU-frequency drift;
  • reports the median of five rounds;
  • has no fragile timing assertion.

Results from Node 24.18 on the same machine:

Mode Items Current optioned localeCompare Lazy reused collator Speedup Time saved/sort
Numeric 36 0.239 ms 0.018 ms 13.2× 0.221 ms
Numeric 50 0.370 ms 0.027 ms 13.6× 0.343 ms
Numeric 250 2.812 ms 0.230 ms 12.2× 2.582 ms
Base sensitivity 10 0.037 ms 0.001 ms 26.6× 0.036 ms
Base sensitivity 50 0.365 ms 0.016 ms 23.3× 0.349 ms
Base sensitivity 250 2.730 ms 0.117 ms 23.3× 2.613 ms

Why these sizes:

  • 36 matches the Linear page size;
  • 50 matches the native picker/Jira scale;
  • 250 is explicitly a stress case, not the ordinary case.

This is a large comparator-level improvement but a modest common-case end-to-end improvement: normal 36–50-row sorts save roughly 0.2–0.35 ms. Palette impact depends on how often earlier score/context fields already decide ordering, and numeric issue sorting is user-selected rather than the default updated-time order. The PR does not claim that the complete UI interaction becomes 13–26× faster.

Screenshots

No visual change. Ordering is deliberately unchanged.

Testing

  • pnpm lint — full repository lint was not run; targeted oxlint passed and pnpm run check:code-quality:changed reported 0 new standard, type-aware, or React Doctor findings across all 9 changed files.
  • pnpm typecheck — the affected renderer target passed with pnpm run typecheck:web; Node and CLI targets are untouched.
  • pnpm test — the full repository suite was not run; 110 focused tests passed across 8 affected palette, Jira, native-chat, open-tab, and comparator test files.
  • pnpm build — not run; no bundler configuration, dependency, native module, or packaging behavior changed.
  • Added differential ordering and lifecycle tests that would catch changed case/accent/numeric/tie semantics, eager initialization, or failure to reuse either collator.

Additional checks:

  • direct sign parity for every pair in mixed case, accent, punctuation, duplicate, and numeric fixtures;
  • complete sorted-array parity against the previous localeCompare expressions;
  • explicit proof that importing the module creates zero collators;
  • explicit proof that repeated calls create only one collator per mode;
  • pnpm run check:max-lines-ratchet passed with no new bypasses;
  • git diff --check passed;
  • the benchmark’s exact-output assertions passed for every measured size.

AI Review Report

The review traced all seven production expressions and verified their exact locale, options, fallback ordering, call frequency, and surrounding sort behavior.

The first implementation eagerly constructed two collators at module load. Review identified that this could shift approximately 5 ms of first-ICU initialization into renderer startup. The implementation was changed to lazy comparator functions, and a regression test now proves both “no construction on import” and “one construction per comparison mode.”

Review also checked:

  • case, accent, punctuation, duplicate, and natural-number ordering;
  • stable ties including TASK-2 versus TASK-02;
  • the native picker’s unchanged optionless path fallback;
  • default-locale behavior on macOS, Linux, and Windows;
  • module-cache lifetime and synchronous initialization;
  • remote/SSH/folder-workspace strings as ordinary renderer inputs;
  • benchmark output parity and measurement-order bias;
  • existing max-lines constraints.

The final independent review found no high- or medium-severity issues. Its benchmark-order concern was addressed by interleaving measurement arms, and its base-mode reuse concern was addressed by exercising that comparator twice in the laziness test.

Security Audit

This change performs no I/O and introduces no new authority boundary.

  • Input handling: existing display strings are passed to the same locale semantics as before.
  • Commands and shells: none added or changed.
  • Filesystem and paths: untouched.
  • IPC and remote wire: no request, event, stream, or serialization shape changed.
  • Authentication and secrets: untouched.
  • Persistence: untouched.
  • Dependencies: no package or lockfile change.
  • Failure behavior: if collator construction throws, assignment does not complete and the next call can retry, matching the synchronous failure boundary of the old comparison.

No security follow-up is required.

Notes

  • No colors, layout, typography, spacing, components, or UX behavior changed.
  • No keyboard shortcuts or platform-specific labels changed.
  • No Git commands or Git-provider behavior changed.
  • SSH and folder workspaces require no special handling because this is renderer-only comparison of already-loaded strings.
  • The PR intentionally does not include the larger AI Vault concurrency idea: that candidate has higher absolute upside for very large histories but needs a global cross-root scheduler and broader Windows/WSL/SSH validation before it meets the zero-regression bar.

@nwparker
nwparker requested a review from brennanb2025 as a code owner August 10, 2026 02:33
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c0dd43f-d484-4b0d-95cd-1fbccd714d77

📥 Commits

Reviewing files that changed from the base of the PR and between ce8c326 and ef5b7c6.

📒 Files selected for processing (9)
  • config/scripts/locale-collator-sort-benchmark.mjs
  • src/renderer/src/components/TaskPage.tsx
  • src/renderer/src/components/jira-issue-sorter.ts
  • src/renderer/src/components/native-chat/native-chat-picker-items.ts
  • src/renderer/src/lib/browser-palette-search.ts
  • src/renderer/src/lib/locale-text-collators.test.ts
  • src/renderer/src/lib/locale-text-collators.ts
  • src/renderer/src/lib/simulator-palette-search.ts
  • src/renderer/src/lib/workspace-tab-palette-results.ts

📝 Walkthrough

Walkthrough

The change adds cached locale-text comparators for numeric and base-sensitivity ordering. Renderer sorting paths now use these shared comparators for issue identifiers, skills, and palette results. Tests verify ordering parity and lazy collator initialization. A benchmark measures sorting performance across deterministic numeric and text datasets.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: reusing renderer locale collators for performance.
Description check ✅ Passed The description covers the summary, visual impact, testing, AI review, security audit, and platform-specific notes with clear scope and results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@nwparker
nwparker merged commit f2b2ece into main Aug 10, 2026
45 checks passed
@nwparker
nwparker deleted the nwparker/perf-lh-renderer-collators branch August 10, 2026 05:24
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