Skip to content

[BUG] 4.5.1: rebuilding children that already carry layout hashes still dispatches one reset per descendant (follow-up to #4121) #4193

Backlog

Description

@romanov-o

Summary

On 4.5.1, rebuilding a list whose items were updated by an earlier callback still dispatches resetComponentState once per rebuilt item. Each dispatch is a separate store notification. In the reproducer below (576 items, 5 idle dcc.Tabs) a click takes 2.76 s on 4.5.1 against 1.59 s on 4.1.0. Removing that one dispatch brings the store notifications back to 4.1.0's count.

A common pattern triggers this: one callback rebuilds a list of items, and another writes into those items through an ALL output, such as counts, classes or labels. From the second update on, every rebuilt item has a layout hash, so the reset fires for each one.

Components whose selector calls determineChangedProps, such as dcc.Tabs, make each notification more expensive. So a page gets slower on 4.5.1 just by having such components, even if they are idle.

Background: #3570 (4.2.0) added this reset to fix #3330, and it was also the main cost behind #3846 and #4121. #3881 (4.5.0) fixed #3846 by removing #3570's other change, a forced remount, but left the reset in place. #4124 (4.5.1) skips the reset when no layout hash is under the component, which fixed #4121 but not this case.

Reproducer

from dash import ALL, Dash, Input, Output, callback, ctx, dcc, html

SCALE = 4   # 576 items in 9 sections
TABS = 5    # idle dcc.Tabs elsewhere on the page
SECTIONS = {f"Field {k}": n * SCALE for k, n in enumerate([6, 60, 40, 5, 10, 3, 15, 2, 3])}


def count(value, shift):
    # Both callbacks write the same value, so their order doesn't matter.
    return str((int(value.split()[-1]) * 7 + 3 * shift) % 100)


def items(field, n, shift):
    out = []
    for v in range(n - (shift % 2)):
        value = f"{field[:3]} {v}"
        out.append(html.Div([html.Span(value),
                             html.Span(count(value, shift), id={"role": "count", "field": field, "value": value})],
                            id={"role": "item", "field": field, "value": value}, className="item", n_clicks=0))
    return out


app = Dash(__name__)
app.layout = html.Div([
    dcc.Checklist(["Show empty"], [], id="toggle"),
    html.Div([html.Div(items(f, n, 0), id=f"section-{k}") for k, (f, n) in enumerate(SECTIONS.items())],
             id="filter-panel"),
    html.Div([dcc.Tabs([dcc.Tab(label="A", value="a"), dcc.Tab(label="B", value="b")], value="a", id=f"tabs-{t}")
              for t in range(TABS)]),
])


@callback([Output(f"section-{k}", "children") for k in range(len(SECTIONS))],
          Input("toggle", "value"), prevent_initial_call=True)
def rebuild(v):
    return [items(f, n, len(v)) for f, n in SECTIONS.items()]


@callback(Output({"role": "count", "field": ALL, "value": ALL}, "children"),
          Input("toggle", "value"), prevent_initial_call=True)
def counts(v):
    return [count(o["id"]["value"], len(v)) for o in ctx.outputs_list]


if __name__ == "__main__":
    app.run(debug=False)

To count the resets, paste this into the browser console and then click the checkbox a few times. It counts notifications in which layoutHashes is the only state slice that changed:

let n = 0, resets = 0, prev = window.store.getState();
window.store.subscribe(() => {
  const cur = window.store.getState(); n++;
  const changed = Object.keys(cur).filter(k => cur[k] !== prev[k]);
  if (changed.length === 1 && changed[0] === 'layoutHashes') resets++;
  prev = cur;
});

From the second click on, 4.1.0 gives 1,177 notifications per click, none of them resets. 4.5.1 gives 1,744, of which 567 are resets: about one per rebuilt item.

Results

Main-thread CPU per click: medians of clicks 3–8 over 3 alternating rounds, using TaskDuration from CDP Performance.getMetrics. The panel text was identical on both versions at every step.

Setup: Python 3.14.5, macOS arm64, Chrome 158, React 18.3.1, debug=False.

Items Idle dcc.Tabs 4.1.0 4.5.1 4.5.1 / 4.1.0 Resets per click on 4.5.1
144 0 144 ms 162 ms 1.12 135
288 0 433 ms 513 ms 1.19 279
576 0 1,548 ms 2,122 ms 1.37 567
576 5 1,589 ms 2,757 ms 1.74 567
576 20 1,700 ms 4,328 ms 2.55 567
  • On 4.1.0, the 20 idle Tabs add about 150 ms. On 4.5.1 they add about 2,200 ms.
  • On a production dashboard built with dash-mantine-components and dash-ag-grid, a filter toggle with this pattern takes 645 ms on 4.1.0, 1,256 ms on 4.5.0 and 1,459 ms on 4.5.1. There, the expensive selectors belong to four dmc.Tooltips and a dmc.MenuDropdown in the page header. I counted determineChangedProps calls on that page: 1,500 per toggle on 4.5.1 against 210 on 4.1.0. I did not count them in the reproducer above.

Expected behavior

The click should cost about what it does on 4.1.0, with a handful of store notifications per callback output, not one per rebuilt item.

Cause

DashWrapper.tsx on v4.5.1, lines 507–510 still dispatches once per wrapper from its _newRender effect:

if (hasFreshRendered.current) {
    dispatch(resetDescendantHashes(componentPath) as any);
}
hasFreshRendered.current = true;

resetDescendantHashes dispatches resetComponentState whenever a key in layoutHashes is at or under the path. In this reproducer each rebuilt item has a hash from the previous counts update, so the check passes for every item. Each of those dispatches is a separate store notification and re-runs every subscribed wrapper's selector.

For components with dashChildrenUpdate, that selector is determineChangedProps. It walks every entry in layoutHashes and splits two path strings for each. So per click the cost is roughly (resets) × (such components) × (layout hashes), which is why the idle Tabs matter.

The reset is the cost. I removed only the resetDescendantHashes dispatch above from 4.5.1's dash_renderer.dev.js, and served it in place of the production bundle to a debug=False server. Store notifications per click dropped to 4.1.0's count, and no resets remained. To keep the comparison fair, all three columns below use dev bundles. Same method as the tables above, and the panel text was identical across all three at every step:

Items Idle dcc.Tabs 4.1.0 4.5.1 4.5.1, dispatch removed Notifications (4.1.0 / 4.5.1 / removed)
144 0 158 ms 186 ms 114 ms 313 / 448 / 313
576 5 1,782 ms 3,015 ms 993 ms 1,177 / 1,744 / 1,177
576 20 1,919 ms 4,616 ms 1,056 ms 1,177 / 1,744 / 1,177

With the dispatch removed, 4.5.1 is faster than 4.1.0, and the idle Tabs cost almost nothing. I did not test the removal against #3330, the bug the reset exists to fix, so I'm not proposing it as the fix.

The same renderer code is on dev as of 2026-11-25.

Activity

  1. added
    bug
    performance
    regression
    dash-renderer
    P2
    sev-2
    on Nov 25, 2026
  2. added theissue type on Nov 25, 2026
  3. self-assigned this
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2bugdash-rendererperformanceregressionsev-2size: 3

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions