Skip to content

perf(mobile): reuse Linear grouping between list and board - #20431

Merged
nwparker merged 2 commits into
mainfrom
nwparker/perf-mobile-linear-grouping-reuse
Sep 13, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/perf-mobile-linear-grouping-reuse

Conversation

@nwparker

@nwparker nwparker commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​421 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​419
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 0

What

useMobileTasksProviderViewProjection grouped the same pre-sorted Linear issue list twice per
render: once for the list sections and once for the board columns. For every grouping except
none, those two calls receive identical arguments and produce identical sections, so the board
now reuses linearIssueSections. none keeps its own status grouping, because the list
collapses to a single "Issues" section while the board still needs one column per status.

Six lines changed in mobile/src/tasks/use-mobile-tasks-provider-view-projection.tsx; the memo
body becomes a ternary and linearIssueSections joins its dep array.

Behavior preserved

Sections, their order, keys, labels, colors, and per-section issue order are asserted equal to the
pre-change implementation (kept verbatim inline in the test as an oracle) across all five groupings
x three orderings. The none branch is byte-identical to the old code, including its separate
board grouping. The new dep linearIssueSections is a strict function of the three deps already
present, so there is no added or missed invalidation.

The one observable difference is that linearBoardSections and linearIssueSections are now the
same array object when grouping is not none. Both consumers are read-only: mobile-tasks-linear-list.tsx
maps over them, and the hook flat-maps them into linearListEntries. A search over mobile/src
found the only write to section.issues is the build-time push inside groupLinearIssues
itself; no sort, splice, or reverse on a section anywhere. A test asserts section shapes are
unchanged after linearListEntries is built.

Measurement

Operation counts for one mount with 50 grouped issues, from a real React mount measured against the
inline pre-change oracle. Instrumented with a wrapping groupLinearIssues plus a scoped
Array.prototype.sort comparator counter. Command:

cd mobile && vitest run src/tasks/use-mobile-tasks-provider-view-projection.test.tsx
grouping calls per-issue grouping visits sort-comparator calls
before 2 100 316
after 1 50 267

Byte-identical across three consecutive runs. With none, all three counts are unchanged
(2 / 100 / equal), which is asserted.

Two caveats on these numbers:

  • Only 2 -> 1 grouping calls and 100 -> 50 issue visits are engine-independent.
  • The comparator drop of 49 is n - 1 because the removed pass re-sorted an already-sorted array
    under V8's TimSort in Node. The app itself runs Hermes, whose sort is a different algorithm, so
    the shape of that delta does not transfer to the device. 316 -> 267 is a 15% cut of the
    comparisons in the measured window, not a halving — most of the remainder comes from the
    linearIssuesForView sort, which this PR does not touch.

These are operation counts. They are not time, CPU, latency, throughput, or heap.

Tests

New mobile/src/tasks/use-mobile-tasks-provider-view-projection.test.tsx: 17 cases, 415 lines,
react-test-renderer, matching the existing mobile hook-test idiom. Coverage: board/list array
identity per grouping, none separation, full parity against the oracle for every grouping x
ordering, grouping transitions, order transitions, unrelated rerenders, list/board view switches,
refreshed-but-equal arrays, non-mutation, and the differential counts.

Does CI run this? Yes — with one live caveat you should know before trusting it.

  • .github/workflows/mobile.yml (job verify) triggers on any PR touching mobile/** and runs
    pnpm test with working-directory: mobile. That resolves to vitest run against
    mobile/vitest.config.ts, whose include is src/**/*.test.ts and src/**/*.test.tsx. This
    file matches. (config/vitest.config.ts is the desktop suite and covers only src/**,
    config/scripts/** and tests/** — mobile has its own separate runner, not a missing one.)
  • Caveat: the step before the test step in that job, pnpm install --frozen-lockfile, fails
    at HEAD. I reproduced it on a pristine temp copy of HEAD's own mobile/package.json,
    pnpm-lock.yaml, pnpm-workspace.yaml and patches/, under both the repo-pinned pnpm 12.0.0
    and pnpm 10.33.2: ERR_PNPM_LOCKFILE_CONFIG_MISMATCH ... "patchedDependencies" configuration doesn't match the value found in the lockfile — even though all three patch sha256s match the
    lockfile byte-for-byte. This is pre-existing on HEAD and unrelated to this PR, but if it also
    reproduces on the GitHub runner then the Mobile Checks job never reaches its Test step and this
    file is effectively local-only until the lockfile is repaired. I could not verify the runner's
    behavior
    (no CI runs inspected). Do not assume this test is guarding the change in CI until
    you have seen a green Mobile Checks run on this PR.
  • Typecheck does not cover it. mobile/tsconfig.json sets "exclude": ["**/*.test.ts", "**/*.test.tsx"], so pnpm typecheck skips every mobile test file, this one included. That is a
    deliberate repo-wide posture — mobile/vitest.config.ts sets oxc: { tsconfig: false } with a
    comment naming exactly this reason — not something this PR introduces, but it does mean a type
    error in this file would surface only as a runtime test failure.

Local commands and results:

  • cd mobile && vitest run src/tasks/use-mobile-tasks-provider-view-projection.test.tsx -> 17 passed (1 file).
  • Same command with the source hunk reverted to HEAD -> 10 failed / 7 passed. The 7 survivors
    are the parity and none cases, which are supposed to hold either way.
  • oxlint --config mobile/.oxlintrc.json src/tasks/ -> exit 0 (oxlint does lint test files).
  • oxfmt --check -> clean. No max-lines disable and no per-file bump added.

Trimmed from the first draft: dropped a label/color self-consistency case already subsumed by the
oracle parity check, and dropped three parameterized repeats of the comparator-delta assertion,
which restated an engine-specific invariant without adding independent coverage. 441 -> 415 lines,
21 -> 17 cases.

ELI5

The tasks screen bucketed your Linear issues into groups twice in a row and threw one copy away —
like alphabetizing the same deck of cards twice and only using the second result. Now it does the
work once and hands the same stacks to both the list view and the board view. The single case where
the two views genuinely need different stacks — "no grouping", which is a flat list but still has
status columns on the board — still does its own separate pass. You will not perceive any
difference: nothing looks different, nothing moves faster in a way you could notice, and no setting
changes. This is invisible tidying, not a speed-up you can feel.

Merge risk

Low. Blast radius is the Linear list and board on mobile; nothing else imports these values. The
riskiest line is : linearIssueSections — the branch that hands the list's array to the board. If
the reasoning were wrong (a consumer mutates a section, or the two groupings were not actually
identical for some grouping) the two views would corrupt each other's contents or show wrong
columns, which would show up immediately as duplicated or missing issues, or a wrong column header,
on the Linear tab. The memo body is self-contained, so revert is a one-hunk change.

The real residual risk is not the code, it is the evidence: see the CI caveat in Tests.

User-facing trade-offs

None identified. What justifies that:

  • Shape-level parity (keys, labels, colors, per-section issue order) against the pre-change
    implementation for all 5 groupings x 3 orderings.
  • Array-identity and non-mutation assertions across both consumers, plus a repo-wide search
    confirming both are read-only.
  • none asserted unchanged in both output and operation counts.
  • A real mount/update/unmount lifecycle via react-test-renderer, not a simulated memo.
  • Allocation moves in the safe direction — one fewer sections array and one fewer per-section array
    allocated per render, and no new retention, since the board now points at an object the list
    already holds instead of keeping a second copy alive.

What is unproven:

  • No CI run has been observed. Per the caveat above, the mobile job may not even reach its test
    step at HEAD.
  • mobile pnpm typecheck and mobile pnpm lint were never run as CI runs them, because the mobile
    lockfile does not install. Lint was run directly with the mobile oxlint config; typecheck would
    skip this file regardless.
  • No iOS or Android device or simulator run, and no rendered screenshot of the board.
  • No wall-clock, CPU, or memory measurement of any kind — only operation counts in Node.
  • Behavior on Hermes was not measured; the engine-independent claims (2 -> 1 calls, 100 -> 50
    visits) are structural, but the comparator numbers are Node/V8 only.

Limitations

The test suite was run with the repository's root vitest 4.1.11 binary against
mobile/vitest.config.ts, with react and [email protected] symlinked into the
gitignored mobile/node_modules plus an expo/tsconfig.base.json stub, because
pnpm install --frozen-lockfile fails at HEAD (see Tests). That is the same config and the same
vitest major CI would use, but it is not a full mobile dependency tree.

The comparator count is measured by patching Array.prototype.sort during the measured window, so
it reflects V8's TimSort; the asserted n - 1 invariant would need revisiting on another engine.
All counts come from a single fixture of 50 issues with a fixed field distribution, so they do not
characterize large workspaces.

This PR removes the duplicate grouping pass only. The projection still re-groups from scratch
whenever items, the grouping, or the ordering change — that cost is unchanged.

@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: 07d5025d-315f-4fb8-9ff0-9b0fc89aa927

📥 Commits

Reviewing files that changed from the base of the PR and between 67726aed657187e4a8d22c78be140dc5989066ca and af1a312.

📒 Files selected for processing (3)
  • mobile/src/tasks/mobile-tasks-refactor-parity.test.ts
  • mobile/src/tasks/use-mobile-tasks-provider-view-projection.test.tsx
  • mobile/src/tasks/use-mobile-tasks-provider-view-projection.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • mobile/src/tasks/mobile-tasks-refactor-parity.test.ts

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


📝 Walkthrough

Walkthrough

The hook now reuses linearIssueSections for grouped board views and keeps separate status grouping for none. New tests verify projection parity, object identity across rerenders and view changes, refreshed-array behavior, and grouping and sorting work counts. Refactor parity hashes were updated for the changed hook output.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to af1a3

The production projection change has parity and transition coverage, but one performance-oriented test may be flaky on supported JavaScript engines despite correct behavior. This is a bounded test-maintenance risk rather than a production regression.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives detailed scope, rationale, behavior preservation, testing, limitations, and risk information. However, it omits the required Linked Issue section and Visual Proof section, and it… Add a Linked Issue with the issue reference, add a Visual Proof section with N/A and a reason if there is no visual or interaction change, and include the required Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and …
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: reusing Linear grouping between the mobile list and board.
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.
Full details: Description check

Explanation

The description gives detailed scope, rationale, behavior preservation, testing, limitations, and risk information. However, it omits the required Linked Issue section and Visual Proof section, and it does not include the repository checklist sections.

Resolution

Add a Linked Issue with the issue reference, add a Visual Proof section with N/A and a reason if there is no visual or interaction change, and include the required Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections as applicable.

  • 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

  • Board reuses list sections — linearBoardSections now returns linearIssueSections for every grouping except none, which still computes its own status split for columns.
  • Memo deps widened — linearIssueSections joins the board memo's dep array; since it is a pure function of the existing (linearGroupBy, linearIssuesForView, linearOrderBy) deps, invalidation is unchanged.
  • New parity test suite — 17 cases in mobile/src/tasks/use-mobile-tasks-provider-view-projection.test.tsx assert board/list array identity, byte-for-byte shape parity against the kept pre-change implementation across 5 groupings × 3 orderings, transition/identity behavior, non-mutation, and differential grouping counts.

The aliasing between linearIssueSections and linearBoardSections is safe: groupLinearIssues sorts a copy and allocates fresh section arrays, and both consumers (mobile-tasks-linear-list.tsx and the hook's linearListEntries flatMap) only read them. A search of mobile/src/tasks confirms the sole section.issues.push is the build-time call inside groupLinearIssues itself.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: dca0d3eb-d285-4b6d-a3b2-66caf4d69d2c

📥 Commits

Reviewing files that changed from the base of the PR and between cf7ce05 and 67726aed657187e4a8d22c78be140dc5989066ca.

📒 Files selected for processing (3)
  • mobile/src/tasks/mobile-tasks-refactor-parity.test.ts
  • mobile/src/tasks/use-mobile-tasks-provider-view-projection.test.tsx
  • mobile/src/tasks/use-mobile-tasks-provider-view-projection.tsx

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

expect(before.issueVisits).toBe(100)
expect(after.issueVisits).toBe(50)
// The dropped grouping re-sorted an already sorted 50-issue array: n-1 comparisons.
expect(before.comparisons - after.comparisons).toBe(input.items.length - 1)

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Remove the engine-specific sort-count assertion.

countLinearWork counts calls to the comparator passed to Array.prototype.sort. The JavaScript specification does not guarantee that count. The groupingCalls and issueVisits assertions already verify the duplicate grouping reduction.

Proposed fix
-    // The dropped grouping re-sorted an already sorted 50-issue array: n-1 comparisons.
-    expect(before.comparisons - after.comparisons).toBe(input.items.length - 1)

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

Important

The new parity-hash regeneration is correct for this branch's base, but main has since rewritten the same test and this branch now conflicts on mobile/src/tasks/mobile-tasks-refactor-parity.test.ts. Rebase and regenerate rather than keeping these values.

Reviewed changes

  • Regenerated refactor parity hashes — 67726aed updates PRE_REFACTOR_SCREEN_HOOKS and PRE_REFACTOR_STATEMENTS in mobile-tasks-refactor-parity.test.ts to match the linearBoardSections memo edit from the previous commit; the other five constants are unchanged.
  • Verified the parity suite passes 6/6 at 67726aed, with mobile/node_modules/typescript symlinked to the repo's [email protected] and a stubbed expo/tsconfig.base.json (mobile deps are not installed in this checkout).

⚠️ Parity constants are stale against main and the file conflicts

This branch is based on cf7ce05827…, where the constants were still named PRE_REFACTOR_*. main has since landed #20233 and #20249, which rewrite the same file: every constant is renamed to EXPECTED_*, four values change (SCREEN_HOOKS, STATEMENTS, DECLARATIONS, SEMANTICS), and a comment is added. A three-way merge conflicts on exactly the constant block at lines 19-25. Because both sides edit those lines, resolving the conflict by keeping this branch's side would revert main's rename and baseline updates, and the two values regenerated here are also computed without main's source changes. Rebase onto main, keep the EXPECTED_* naming and values, and regenerate only the constants that diverge after the rebase.

Technical details
# Rebase and regenerate refactor parity hashes

## Affected sites
- `mobile/src/tasks/mobile-tasks-refactor-parity.test.ts:19` — `PRE_REFACTOR_SCREEN_HOOKS`/`PRE_REFACTOR_STATEMENTS` regenerated against a base `main` has replaced.
- `mobile/src/tasks/mobile-tasks-refactor-parity.test.ts:19-25` — conflict block vs `origin/main` (renamed to `EXPECTED_*`; `DECLARATIONS`/`SEMANTICS` values and counts also changed).

## Evidence
- `git merge-base origin/main HEAD` = `cf7ce05827…`; `origin/main` has `a045af3618` and `701dc2211c` on this file after that.
- `git merge-file -p --diff3 HEAD <base> origin/main` exits 1 with a conflict spanning lines 19-25.
- `origin/main` also adds `// Task and Linear sort tests cover computation changes; render/style guards remain.`

## Required outcome
- After rebasing onto `main`, the `use-mobile-tasks-provider-view-projection.tsx` edit should move only the hook/statement hashes on top of `main`'s `EXPECTED_*` constants, without dropping `main`'s rename or its other baseline updates.

## Suggested approach (optional)
- Rebase onto `main`, run `cd mobile && vitest run src/tasks/mobile-tasks-refactor-parity.test.ts`, and update only the constants that actually diverge.

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

Rebasing onto main surfaced two breakages that the earlier ratchet-only fix
could not have caught, because it was computed against a base main had already
superseded:

- The parity oracle called compareLinearIssues, which #20249 deleted in favour
  of sortLinearIssues. Rewrote the oracle to use sortLinearIssues, matching what
  the production memo now calls, and dropped the stale mock override.
- Regenerated EXPECTED_SCREEN_HOOKS and EXPECTED_STATEMENTS from an observed run
  on the rebased tree. Arity assertions (350 hooks, 417 statements) unchanged.

mobile/src/tasks: 37 files, 295 tests pass.
@nwparker
nwparker force-pushed the nwparker/perf-mobile-linear-grouping-reuse branch from 67726ae to af1a312 Compare September 13, 2026 03:17
@nwparker

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and corrected the parity work.

The earlier ratchet-only fix regenerated hashes against cf7ce05827c, but main had already superseded that base ~90 minutes earlier (701dc2211c3, a045af36187 renamed PRE_REFACTOR_* -> EXPECTED_* and moved the arities). That turned a mergeable PR into a conflicting one and baked in hashes that were wrong for the post-merge tree. Dropped that commit and redid it properly.

Rebasing then surfaced a second, more substantive breakage the ratchet fix could not have caught: the parity oracle called compareLinearIssues, which #20249 deleted in favour of sortLinearIssues. All 17 tests in the new suite were erroring, not just the two ratchet assertions. Rewrote the oracle to call sortLinearIssues, matching what the production memo now calls, and dropped the stale mock override.

  • EXPECTED_SCREEN_HOOKS / EXPECTED_STATEMENTS regenerated from an observed run on the rebased tree (not pasted).
  • Arity assertions unchanged: 350 screen hooks, 417 statements.
  • mobile/src/tasks: 37 files, 295 tests pass.

Also worth recording, since an earlier pass of mine got this wrong: this PR and #20314 are not duplicates. They optimize orthogonal halves of the same expression — this one removes a duplicate groupLinearIssues call, #20314 swaps in groupSortedLinearIssues to drop the redundant internal re-sort. They conflict textually only; the ideal end state is both. This PR is the better near-term candidate (main-based, 6 production lines), so #20314 should rebase on top of it.

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

The prior must-address concern — the branch conflicted with main on the refactor parity file and carried stale baseline values — is resolved. HEAD is now rebased onto main (5127d1eb is an ancestor of af1a312958), the file adopts main's EXPECTED_* naming and values, and only the two hashes the source edit actually moves are regenerated. I re-ran both mobile test files locally and they are green.

Reviewed changes

  • Rebased onto current main — af1a312958 replays the branch on 5127d1eb, so the refactor parity file no longer conflicts and the conflict-resolution problem from the previous review is gone.
  • Regenerated only the moved parity baselines — EXPECTED_SCREEN_HOOKS and EXPECTED_STATEMENTS were recomputed for the linearBoardSections memo edit; EXPECTED_DIFF_HOOKS, EXPECTED_DECLARATIONS, EXPECTED_SEMANTICS, EXPECTED_STYLES and EXPECTED_RENDER_TREE keep main's values. The length assertions (350 / 417 / 192 / 3,500 / 35,195) are unchanged.
  • Adapted the new projection test to main's sort helper — the oracle now calls the shared sortLinearIssues(issues, orderBy) instead of the removed compareLinearIssues comparator, and the mobile-tasks-legacy-foundation mock spreads ...linear so sortLinearIssues is exposed alongside the wrapped groupLinearIssues.

Verification this run (mobile dependencies are not installed in the checkout, so this used the repo vitest 4.1.11 with mobile/vitest.config.ts, mobile/node_modules/typescript symlinked to the pinned [email protected], a stubbed expo/tsconfig.base.json, and [email protected] deduped to the repo's react):

  • vitest run src/tasks/mobile-tasks-refactor-parity.test.ts → 6 passed.
  • vitest run src/tasks/use-mobile-tasks-provider-view-projection.test.tsx → 17 passed.

The production diff in this PR is unchanged from the version previously approved, and both consumers of the shared sections remain read-only.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 7e9ade7 into main Sep 13, 2026
22 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