SIGN IN SIGN UP
payloadcms / payload UNCLAIMED

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.

0 0 16 TypeScript

perf(richtext-lexical): 3-15x less main thread blocking via centralized toolbar state (#15832)

Replaces per-component `editor.registerUpdateListener` subscriptions in
toolbar buttons and dropdowns with a single centralized
`useToolbarStates` hook that computes all active/enabled states in one
pass. Previously every keystroke triggered 15+ independent React state
updates across toolbar items - now it triggers one.

`ToolbarButton` and `ToolbarDropdown` are now stateless presentational
components. The dropdown icon/label derivation that previously used a
`useState`/`useEffect`/`onActiveChange` callback loop is replaced with a
direct `useMemo` from `groupState.activeItems`.

Also adds a dedicated benchmark suite (`test/lexical/benchmarks/`) with
CPU-throttled typing for tracking performance.

## Benchmark Results (6x CPU throttle)

### Empty Editor

| Metric | Before | After | Change |
|--------|--------|-------|--------|
| Mean AvgLag | 10.05ms | 11.09ms | ~same |
| Long Tasks | 68.4 | 4.2 | -94% |
| Long Task Duration | 4315ms | 277ms | **15x less** |

### With 30 Blocks

| Metric | Before | After | Change |
|--------|--------|-------|--------|
| Mean AvgLag | 15.96ms | 14.88ms | ~same |
| Long Tasks | 26.6 | 2.8 | -89% |
| Long Task Duration | 2838ms | 844ms | **3.4x less** |

Main thread blocking dropped 3x with 30 blocks in the editor and 15x on
an empty editor. I ran this test multiple times, and the results for
both before and after were consistently in a similar range.

In practice, typing in the editor should feel smoother, especially on
slower devices or in documents with lots of blocks and fields.
A
Alessio Gravili committed
2bdf7ce006d8b42729a534c2f825eb4519c2be2a
Parent: fba2438
Committed by GitHub <noreply@github.com> on 3/6/2026, 7:06:04 PM