Repository navigation
perf(metrics): keep unchanged metric panels stable when another panel changes - #128357
Conversation
Sentry Snapshot Testing
|
📊 Type Coverage Diff
🔍 2 new type safety issues introducedNon-null assertions (
This is informational only and does not block the PR. |
… changes Row mutators hand updater functions to setQueries instead of closing over the rendered queries, and decoded queries are cached per URL value and index, so unchanged panels keep the same query params and mutators. The URL-backed provider moves onto nuqs, whose setter is stable and composes queued writes.
3de35e2 to
f512f71
Compare
…lapsing-metrics' into joshgoldberg/logs-1035-functional-metric-query-setters
…lapsing-metrics' into joshgoldberg/logs-1035-functional-metric-query-setters
Index-bound mutators edited the wrong row when captured before an earlier row was removed. Adds coverage for unrelated URL changes, no-op writes, and history pushes.
Labels can repeat after an external navigation that keeps the row count, so mutators resolved by label could edit or remove the wrong row.
nuqs only tracks its own writes after the provider's effects subscribe, so a second write during the mount commit started from the stale URL and dropped the first.
Also keeps the useStableLabels docblock attached to the hook.
| // nuqs keeps its URL update queue in a global, and only its own testing | ||
| // adapter clears it on mount, so a previous test's pending write would | ||
| // otherwise become this test's initial state. The inner provider overrides | ||
| // its adapter. |
There was a problem hiding this comment.
[Question] Is this, like, a known nuqs thing? It confused me at first, which is why I didn't delete this AI-y comment the way I normally do...
There was a problem hiding this comment.
Hrrm, this may be a bigger question for @TkDodo
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 184ec89. Configure here.
nsdeschenes
left a comment
There was a problem hiding this comment.
Things look good to me, but worth taking a peek at those cursor comments.
…order Adding and reordering panels now write through updater functions, so they no longer overwrite row edits that haven't been applied yet. Row mutators are cached per row id, and the decode cache evicts least recently used entries keyed by value occurrence, so panels that only shift position keep their identity. Refs LOGS-1035
59d7274
into
joshgoldberg/logs-1035-reduce-lag-when-expanding-or-collapsing-metrics
…es (#126977) Problem: Expanding or collapsing a metric panel writes to the URL. Every panel re-decoded its query params from the URL, and table rows and cells subscribed to the location for their links. So any expansion/collapse -> causes a URL change -> causes every component in every other panel to re-render. This PR fixes it with a few things: * Sample rows only read the location in their trace link cell, and Explore field cells keep their cell action menus out of location-driven re-renders. * Embedded sample tables keep their rows memoized even when their query is disabled. * Button tracking also returns a stable function As part of this I extracted `renderTraceCell` out into a `TraceLinkCell` component. Keeping unchanged panels' query params and mutators stable is split out into #128357. Together with getsentry/sentry-javascript#25336 I think this should fix much of the perf issues around metrics panel toggles. | Collapsing one of three metric panels (median of 12) | Prod | This PR's preview | Delta | | --- | --- | --- | --- | | Main-thread busy time | 159ms | 128ms | −20% | | Components re-rendered | 9,894 | 1,839 | −81% | | React commits | 7 | 4 | −43% | Closes LOGS-1035.

Unchanged metric panels now keep the same query params and mutators when another panel changes, because row mutators hand updater functions to
setQueriesinstead of closing over the rendered queries.This is done by:
setQueriesnuqsand its nice stable setternuqs's global URL update queue between tests in the shared test adapterRapid edits now coalesce into a single history entry, since
nuqsbatches URL writes.Split out of #126977 so we don't have to use esoteric React hooks. Thanks for prodding me on the docs @nsdeschenes 😄