Skip to content

rfc(Table): skip unused press handling in RAC Table cells (RFC + benchmarks) - #11083

Open
coolassassin wants to merge 2 commits into
adobe:mainfrom
coolassassin:rfc-2026-table-cell-without-press
Open

coolassassin wants to merge 2 commits into
adobe:mainfrom
coolassassin:rfc-2026-table-cell-without-press

Conversation

@coolassassin

@coolassassin coolassassin commented Dec 4, 2026 •

Copy link
Copy Markdown

Closes

Summary

Every RAC Cell calls useTableCell → useGridCell → useSelectableItem, which runs two usePress instances (one directly, one inside useLongPress), useLongPress and useRouter on every render. In RAC and S2 tables none of these handlers ever reach the cell element:

  • there is no cell selection (allowsCellSelection is never set, so canSelectItem(cellKey) is false);
  • there is no onCellAction (RAC Table doesn't pass it, S2 omits it) and cells have no href.

Presses are handled by the row, and the cell's isPressed is always false.

This PR adds a private useTableCellWithoutPress (react-aria/private/table/useTableCellWithoutPress) and uses it in the RAC Cell. It keeps everything the cell actually needs:

  • roving tabIndex, onFocus, and the focus-on-focusedKey effect;
  • the disabled branch;
  • data-key / data-collection and the auto id;
  • the child-interaction guard that keeps presses on inputs or nested collections from selecting the row;
  • all of useGridCell's focus and keyboard logic.

To avoid duplication, useSelectableItem and useGridCell are split into shared helpers. The public useTableCell, useGridCell and useSelectableItem keep their behavior and hook order, so v3, the starters and third-party users are unaffected.

The design, a list of the behavior that is preserved, the compatibility analysis and the benchmarks are in the RFC included in this PR: rfcs/2026-table-cell-without-press/README.md.

Benchmarks

Production React 19.3, minified bundles built from source, headless Chromium, medians of 10 alternating A/B iterations. Scripts and raw results are in rfcs/2026-table-cell-without-press/bench/.

Scenario Hooks / body cell Mount Selection update Retained heap
100 × 10 127 → 60 −22% −34% 23.1 → 14.2 MB (−38%)
500 × 10 127 → 60 −22% −33% 113.3 → 68.9 MB (−39%)
1,000 × 10 127 → 60 −19% −34% 226.0 → 137.2 MB (−39%)
10,000 × 10, Virtualizer 135 → 68 ≈0 ≈0 −2.4%

For the virtualized table, main-thread time while scrolling (40 steps of 1600px) is −14%. Only about 300 cells are mounted there, and mount and update time is dominated by building the 10,000-row collection. The per-cell saving is the same in every scenario: 8.9 KB of retained heap.

Report with details:
Lighter RAC Table Cells.html

📝 Test Instructions

  • yarn check-types, oxlint and oxfmt --check on the changed files, and node scripts/lint-packages.js: pass.
  • yarn test packages/react-aria packages/react-aria-components packages/@react-spectrum/s2 on Node 22: 3261 passed, 48 failed.
    • All table suites pass: RAC Table (except 3 Mod+A tests), Treeble, S2 TableView and EditableTableView, useTable, useGrid. This includes the tests for clicking a tabbable child or a nested TagGroup inside a cell.
    • The 3 Mod+A failures are Symbol.dispose is not defined and fail the same way on unmodified main.
    • The other 45 failures are in unrelated suites: Button, Focusable, Pressable, usePress, LandmarkManager and others.
  • The 16 failing suites re-run on Node 24 (the version in .nvmrc): 532 passed, 1 failed. The failure is DateField › era with no localized name, which depends on the ICU data in Node and does not touch the changed code.
  • Benchmark: see rfcs/2026-table-cell-without-press/bench/README.md.

Not verified yet: a manual pass in Storybook (draggable rows, cells with text fields in both focus modes, focus restoration in virtualized tables, touch long press on rows), and benchmarks on other machines or in Firefox and Safari.

Release impact

  • Only changes docs, tests, CI, or development tools. Nothing shipped to users changes.
  • Fixes a bug or improves existing code without changing how apps use it.
  • Adds a feature or API while keeping existing usage working.
  • May break existing usage or require changes in apps that use this code.

One edge case: RAC Table spreads unknown props into useTable, so from untyped JavaScript it is possible today to pass onCellAction to Table, or href to Cell, and get pressable cells. Neither prop is typed or documented. After this change such presses stop working, and a one-time development warning points to onRowAction and links on rows.

✅ PR Checklist

  • I followed the contributing guide.
  • I tested this change locally and included the results in Test Instructions, or explained why testing does not apply.
  • I understand and can explain every change in this PR. If I used AI assistance, I followed the AI contribution guidance.

AI use: the analysis, implementation, benchmark and RFC were written with Claude Code (Claude Opus 5.5).

🧢 Your Project

dxFeed

Dmitrii Kamenskikh and others added 2 commits December 4, 2026 15:50
RAC Table cells never attach the press props set up by useSelectableItem:
there is no cell selection and no onCellAction, so presses are handled by
the row. Still, every cell ran two usePress instances, useLongPress and
useRouter on every render.

Add a private useTableCellWithoutPress (react-aria/private/table) that keeps
the cell's focus management, keyboard navigation, data attributes and the
child-interaction guard, and use it in the RAC Cell. Shared logic is
extracted from useSelectableItem and useGridCell; the public useTableCell,
useGridCell and useSelectableItem keep their behavior and hook order.

Hooks per body cell go from 127 to 60, and retained heap drops by 8.9 KB
per mounted cell in production React. See
rfcs/2026-table-cell-without-press for details and benchmarks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…andling

Includes the A/B benchmark (production React, headless Chromium) used to
measure hooks per cell, retained heap, mount, selection update and scroll
time, with the raw results of the last run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coolassassin coolassassin changed the title feat(Table): skip unused press handling in RAC Table cells (RFC + benchmarks) rfc(Table): skip unused press handling in RAC Table cells (RFC + benchmarks) Dec 4, 2026
@coolassassin

coolassassin commented Dec 4, 2026 •

Copy link
Copy Markdown
Author

Update: going further than this PR

On top of this PR (127 → 60 hooks per body cell), I tried two more steps. Neither changes the public API, the render props or the data-* attributes.

  • Stage 2 (60 → 47 hooks): cells no longer call useId and useLocale. The cell id comes from the deterministic getCellId, and the layout direction is read once by useGrid and shared through gridMap.
  • Stage 3 (47 → 17 hooks): useFocusRing and useHover are no longer called in every Cell. A table-level focus/hover store, fed by handlers on the table element, replaces them, and each cell reads its own state with a single useSyncExternalStore.

1,000 rows × 10 columns, production React, medians of 10 runs:

main this PR + stage 2 + stage 3
Hooks per body cell 127 60 47 17
Retained heap 226 MB 137 MB 121 MB 85 MB (−62%)
Mount 409 ms 323 ms 309 ms 260 ms (−36%)
Selection update 637 ms 412 ms 387 ms 315 ms (−51%)

In a virtualized table with 10,000 rows, main-thread time while scrolling goes down by 21%, 23% and 28% after each step.

🚀 Report with details

Jest passes on Node 24: 29 suites, 897 tests. I also ran 15 hover and focus checks in a real browser, and they give the same results on main and on stage 3. Stages 2 and 3 are not pushed yet. I'll attach the full report and a follow-up RFC here.

@reidbarber reidbarber left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the thorough investigation and benchmarking here! This is definitely something we want to improve, but I'm hesitant to introduce private forks of public hooks, just for optimizing RAC. A core principle of RAC is that it's built on the same public hooks users can use to build their own similar implementations.

Instead of splitting out a separate cell hook, I think a better solution would be to look for ways to optimize useSelectableItem and usePress directly. This would also benefit other collection items across both RAC and hook consumers.

Two ideas that come to mind are:

  1. Avoiding mounting a second usePress inside useSelectableItem when longPressEnabled is false.
  2. Making usePress cheaper when it is disabled or not used. We could try lazily allocating refs and listener maps, and reducing unnecessary hook/closure overhead in this case.

Also side note, we already have a benchmark suite in perf/, so sharing results from that in the PR description is preferred.

@coolassassin

Copy link
Copy Markdown
Author

Thanks @reidbarber a lot for taking the time to go through the RFC and the benchmarks, and for the pointers, I really appreciate it.

I understand the principle that RAC is built on the same public hooks users can use, and I agree it's valuable. I just don't see a way to optimize the per-element hooks far enough for tables. When every cell is a standalone element that handles its own events and keeps its own state, the cost grows with the number of cells: each cell pays for its own handlers, refs, effects and global listener bookkeeping, even when most of it never fires. Event delegation with a shared store does that work once per table, so it will keep outperforming a per-cell approach, however well tuned.

I also don't think it's a problem to have a dedicated set of hooks and providers for tables and lists. Collections with thousands of items need a different approach than a standalone button, where per-element hooks are a perfect fit.

This doesn't have to conflict with the principle above: the table-level hooks and the shared store don't need to be private. They could be public APIs just like the existing ones (for example, a table-level interaction store plus a lightweight cell hook), so anyone building their own table on react-aria would get the same benefits, and RAC would still be built entirely on public hooks.

About the two ideas: the first one (not mounting a second usePress when long press is disabled) is already tracked in #10775 and being worked on in #10795, so that direction is already covered. What I'm proposing here is a more radical step: instead of making each cell's hooks a bit cheaper, stop running per-cell logic that a table cell doesn't need, and move the rest to the table level.

The main reason is that the hooks tables are built on carry dozens of features that cost something on every render but are never used by a table cell. A few examples:

  • useSelectableItem runs two usePress instances, useLongPress and useRouter for every cell. Cell selection and onCellAction are never enabled in RAC or S2, so none of these handlers ever reach the DOM.
  • Even when its props are not used, each usePress registers with PressResponderContext, syncs refs in a layout effect, and sets up its global listener map and text-selection cleanup effect. useLongPress adds useDescription and its own global listeners on top of that.
  • useId costs 9 hooks and a FinalizationRegistry entry per cell, for an id nothing references (row headers override it with getCellId anyway).
  • useLocale costs 4 hooks per cell and subscribes every cell to languagechange, only to read direction, which useGrid already has.
  • useFocusRing (22 hooks) still mounts useFocusWithin while it's disabled, a focus visible listener per cell, and useSyntheticBlurEvent, whose disabled-input handling can never apply to a cell.
  • useHover (10 hooks) sets up global touch tracking and its own listener map in every cell, just for the isHovered render prop. Cells don't even render data-hovered.
  • The focus effect in useSelectableItem depends on focusedKey, so every arrow key press re-runs it in every mounted cell.
  • Each cell also renders a DOMElement wrapper (3 hooks and an extra fiber) to support the render prop.

Each of these is cheap on its own, but in a table they're multiplied by the number of cells.

Thanks for pointing out the perf/ suite, I wasn't aware of it. I'll run it against these changes as soon as I can and post the results here.

@nwidynski

Copy link
Copy Markdown
Contributor

Could you express, in your own words, what exactly the perceived performance problem is in a virtualized table? I'm not sure what real-world use there is to discuss benchmark improvements to a non-virtualized 1000 row table.

@coolassassin

Copy link
Copy Markdown
Author

@nwidynski Hello! Thanks for reply!

It is my words. I am not native speaker, that is why I use some help from agent
Anyway, I have started this investigation when I found out how many memory my application needs for every table that I see on the screen
Then I found out that one simple cell in RAC consumes 23KB of memory which is crazy and also I found out that one cell - it is 127 React hooks. I saw it because in my memory diagnosis I saw millions of objects from nowhere

I dug deeper and tried to implement lightweight cell which do only necessary things, removed all dead-code inside. Step by step I saw that I can satisfy all RAC tests with less and less memory and with higher performance

You can see this in my report even for virtualised table, when we scroll:
image

Even if we have no big effect for mounting (around 4% for 10000 rows) we have big impact for GC work

Also, I tried to apply my changes to a real-word tables in my app and I removed 80MB of memory. 80MB it a size of huge application, but we spend this for one single table.
And it was just POC for cells. We also can do the same work with table Row component which uses same hooks (or even more)

Just by replacing hooks in cells and in a row we can make a huge impact to memory consumption, reduce GC work and have 30%+ speed up of table scrolling with virtualisation.
For me it sounds reasonable even for my simple POC. I we go deeper we can make table 2 times faster and cheaper, I am sure.

Also, from my perspective it is better to use provider-consumer approach for tables and lists instead of smart cell with tons of hooks. I understand the RAC idea about reuse, but we still can make some better tools for tables and lists to make them reusable and cheaper

I would happy to help you with that if you are also agree about that. I am going to this way anyway, even if it will be my custom code, because I need blazing fast tables with a11y support. But I would be happy to help you to make your great accessible tables more performant for everyone.

It is still just RFC and if you want me more reasonable proofs, I can do additional work with all table components to show how fast it could be without any breaking in terms of API and behavior

@nwidynski

Copy link
Copy Markdown
Contributor

I personally think we should try to break this problem down reasonably. Scroll performance issues likely do not correlate with memory usage. Also, just the number of hooks isn't really indicative of anything. I do agree that 23KB of memory sounds a lot on a per cell basis. I would appreciate a break down of which hooks allocate how much. As @reidbarber already said, we should avoid introducing forks of public hooks, especially for "only" removing press handlers. You should consider that grid edit mode may be added down the line, requiring cell press handlers.

@coolassassin

coolassassin commented Dec 5, 2026 •

Copy link
Copy Markdown
Author

@nwidynski
Hello!

I tried to make a deep research about Cell hooks with memory and usage breakdown. My main aim was to show how big the impact each hook make and how many hooks are useless in the cell, while we use them as is

Full report here

I hope this report could help you to see the picture

You should consider that grid edit mode may be added down the line, requiring cell press handlers.

I don't think that it is a strong argument when potential editing of cell in future should be paid for cells without editing. In this case I would create another pack of hooks (based on same reusable smaller blocks) or make it possible to activate this functionality directly cell by cell via provider.
If we are dealing with text cells - which typically make up 99% of any software - it makes no sense to pay the same price for them as one would for a heavy-duty grid with editable cells.

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.

3 participants