Repository navigation
rfc(Table): skip unused press handling in RAC Table cells (RFC + benchmarks) - #11083
coolassassin wants to merge 2 commits into
Conversation
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>
Update: going further than this PROn 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
1,000 rows × 10 columns, production React, medians of 10 runs:
In a virtualized table with 10,000 rows, main-thread time while scrolling goes down by 21%, 23% and 28% after each step. 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 |
There was a problem hiding this comment.
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:
- Avoiding mounting a second
usePressinsideuseSelectableItemwhenlongPressEnabledisfalse. - Making
usePresscheaper 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.
|
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 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:
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 |
|
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. |
|
@nwidynski Hello! Thanks for reply! It is my words. I am not native speaker, that is why I use some help from agent 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: 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. 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. 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 |
|
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. |
|
@nwidynski 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 I hope this report could help you to see the picture
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. |

Closes
Summary
Every RAC
CellcallsuseTableCell→useGridCell→useSelectableItem, which runs twousePressinstances (one directly, one insideuseLongPress),useLongPressanduseRouteron every render. In RAC and S2 tables none of these handlers ever reach the cell element:allowsCellSelectionis never set, socanSelectItem(cellKey)isfalse);onCellAction(RACTabledoesn't pass it, S2 omits it) and cells have nohref.Presses are handled by the row, and the cell's
isPressedis alwaysfalse.This PR adds a private
useTableCellWithoutPress(react-aria/private/table/useTableCellWithoutPress) and uses it in the RACCell. It keeps everything the cell actually needs:tabIndex,onFocus, and the focus-on-focusedKeyeffect;data-key/data-collectionand the autoid;useGridCell's focus and keyboard logic.To avoid duplication,
useSelectableItemanduseGridCellare split into shared helpers. The publicuseTableCell,useGridCellanduseSelectableItemkeep 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/.VirtualizerFor 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,oxlintandoxfmt --checkon the changed files, andnode scripts/lint-packages.js: pass.yarn test packages/react-aria packages/react-aria-components packages/@react-spectrum/s2on Node 22: 3261 passed, 48 failed.Table(except 3Mod+Atests),Treeble, S2TableViewandEditableTableView,useTable,useGrid. This includes the tests for clicking a tabbable child or a nested TagGroup inside a cell.Mod+Afailures areSymbol.dispose is not definedand fail the same way on unmodifiedmain.usePress, LandmarkManager and others..nvmrc): 532 passed, 1 failed. The failure isDateField › era with no localized name, which depends on the ICU data in Node and does not touch the changed code.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
One edge case: RAC
Tablespreads unknown props intouseTable, so from untyped JavaScript it is possible today to passonCellActiontoTable, orhreftoCell, and get pressable cells. Neither prop is typed or documented. After this change such presses stop working, and a one-time development warning points toonRowActionand links on rows.✅ PR Checklist
AI use: the analysis, implementation, benchmark and RFC were written with Claude Code (Claude Opus 5.5).
🧢 Your Project
dxFeed