Skip to content

perf(mobile): precompute task sort keys and reuse repository collation - #20233

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-mobile-task-sort-keys
Sep 13, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-mobile-task-sort-keys

Conversation

@nwparker

@nwparker nwparker commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​113 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​97
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​139 $\color{#cf222e}{\Huge{\mathbf{−}}}$​23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​116

ELI5

Mobile task sorting now computes dates and repository labels once for each task instead of recomputing them each time two tasks are compared.

What Changed

Replace the two comparator exports with sortMobileTaskItems, called from the existing memo with unchanged dependencies. Decorate tasks with their timestamp and, for repository order, their existing repository label; reuse one current-locale/base-sensitivity collator, then return original task references in sorted order. Empty and singleton inputs still return a fresh array without key setup.

Why

The previous repository comparator repeatedly built metadata (including badge-color hashing), resolved optioned locale collation, and parsed timestamp ties. The update-order comparator repeatedly parsed dates as well.

Counterbalanced Node 24/macOS benchmark, ten samples per arm, synthetic tasks already sorted by update time across 25 repositories. Full output parity is asserted against the actual baseline comparator exports at 20ab9950654.

Tasks Order Before per call After per call
25 Updated 0.0047 ms 0.0032 ms
25 Repository 0.1408 ms 0.0110 ms
1,000 Updated 0.1880 ms 0.1140 ms
1,000 Repository 15.0887 ms 0.5843 ms

At 1,000 tasks, date parses fall from 1,998 to 1,000 for update order and from 4,548 to 1,000 for repository order. At 25 unique repository labels the old repository sort parses no dates and the new sort parses 25; total runtime still decreases. These are helper microbenchmarks, not phone/Hermes latency measurements. The harness resolves the UI dependency barrel's colors export directly to the real theme in both arms so it can run in Node.

Linked Issue

User-requested performance audit; no linked issue supplied.

Visual Proof

N/A — same ordered task references and memo dependencies, with unchanged render/style fingerprints.

Testing

  • ORCA_BACKGROUND_LAUNCH=1 pnpm --dir mobile test src/tasks — 271 tests in 35 files passed.
  • New behavioral/count tests cover GitHub, GitLab, GitLab todos, Linear, repository overrides and refreshes, label fallback, invalid dates, equal-date/label stability, unchanged input references, one date parse per row, no repository lookup for update order, and empty/singleton setup.
  • ORCA_BACKGROUND_LAUNCH=1 pnpm --dir mobile typecheck — passed.
  • Changed-file mobile/root oxlint, format/diff checks, and commit hooks passed.
  • node config/scripts/mobile-task-sort-benchmark.mjs 20ab9950654 reproduces parity and timing/count evidence.

The existing refactor fingerprint suite passed on the unmodified baseline. Four source fingerprints and two counts were updated for this deliberate computation change; hook count, statement count, rendered expressions, diff hooks, and styles retain their existing guards. Constants now say EXPECTED instead of PRE_REFACTOR. Behavioral tests and before/after production comparisons supply the ordering evidence that source hashes alone cannot provide.

Review

Sort keys and collator are per-call, with no persistent cache/invalidation burden. All providers continue using taskRepositoryMeta and the existing taskTime invalid-date fallback. No new Git commands, host execution, RPC fields, filesystem operations, or workspace-kind assumptions; SSH and folder-workspace presentation stay unchanged.

Agent skill upstream boundary

  • Not applicable.

Checklist

  • One focused task-sorting improvement, independent of other audit PRs.
  • Self-reviewed for correctness, security, and performance.
  • Cross-platform, SSH/remote, and folder workspace impact considered.
  • Relevant tests, typecheck, lint, and formatting pass; broader/platform checks remain with CI.

@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 46c07d2a-6a8a-4dd5-b03d-e15d39191fb9

📥 Commits

Reviewing files that changed from the base of the PR and between 9f7fd9a and 71468dd.

📒 Files selected for processing (5)
  • config/scripts/mobile-task-sort-benchmark.mjs
  • mobile/src/tasks/mobile-task-sort.test.ts
  • mobile/src/tasks/mobile-tasks-refactor-parity.test.ts
  • mobile/src/tasks/mobile-tasks-repository-presentation.ts
  • mobile/src/tasks/use-mobile-tasks-picker-projection.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The change replaces separate mobile task comparators with sortMobileTaskItems. The picker projection now uses the shared function for repository and updated sorting. New tests cover ordering, tie handling, identity, immutability, key computation, and short inputs. A benchmark compares the current implementation with a baseline across item counts and sort modes. Refactor parity expectations are updated.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 71468

The sorting refactor is covered by parity and behavior tests with no actionable regression identified.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is detailed and covers the change, rationale, testing, visual impact, review notes, and checklist. However, the required Linked Issue section explicitly states that no issue was suppli… Add a valid linked issue reference after Fixes #. Also add the required AI Disclosure and Notes sections if they apply to this repository workflow, and confirm the full checklist status or CI coverage for any commands not run locally.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main change: improving mobile task sorting performance by precomputing sort keys and reusing repository collation.
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, testing, visual impact, review notes, and checklist. However, the required Linked Issue section explicitly states that no issue was supplied, and the template requires one.

  • Fix all pre-merge checks with AI
✨ 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.

@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 new issues found.

Reviewed changes

Replaces the two exported task comparators with a single key-precomputing sortMobileTaskItems, updates the picker memo to call it, adds focused behavioral/call-count tests, refreshes the refactor-parity fingerprints for the deliberate change, and checks in a benchmark script that asserts output parity against the baseline implementation.

  • sortMobileTaskItems (mobile-tasks-repository-presentation.ts) — decorates each item once with its parsed timestamp and (for repository order) repository label, sorts with a single hoisted Intl.Collator(undefined, { sensitivity: 'base' }), then returns the original task references. The <2 early return mirrors the old [...items].
  • Picker projection (use-mobile-tasks-picker-projection.tsx) — the useMemo body delegates to the helper with unchanged dependencies.
  • Tests — new mobile-task-sort.test.ts pins ordering parity, immutable input, recompute-on-repo-change, and per-item call counts; mobile-tasks-refactor-parity.test.ts renames PRE_REFACTOR_* to EXPECTED_* and updates four hashes plus two counts for the deliberate computation change.
  • Benchmark — config/scripts/mobile-task-sort-benchmark.mjs loads the baseline file at the given ref and the current file, asserts deepEqual ordering, and reports counterbalanced timings plus Date.parse counts.

The comparator rewrite is behaviorally exact: (collator?.compare(...) ?? 0) || b.updatedAt - a.updatedAt reproduces the old labelCompare || updatedCompare, and the array is stable, so ties keep input order. The removed comparator exports have no remaining consumers.

ℹ️ Collation equivalence is asserted on V8, not Hermes

The parity test and benchmark both run under Node/V8 while the shipping engine is Hermes. The Intl.Collator this PR switches to is supported on Hermes in RN 0.83 / Expo 55 (Hermes builds with HERMES_ENABLE_INTL on both platforms, and String.prototype.localeCompare routes through the same native Collator::create/compare), so the ordering is unchanged and nothing needs to change here. Noting it only because CI would not catch a future engine-level divergence between the two APIs.

Pullfrog  | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 701dc22 into main Sep 13, 2026
30 checks passed
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