Skip to content

Possible memory leak in ticking plotly express charts #179

@mattrunyon

Description

@mattrunyon

Description

There seems to be a possible memory leak in the plotly-express JS code when plotting a ticking table. It might only be when plotting within a dh.ui panel, but it is definitely exacerbated by it. With dh.ui memory grew from 100-700MB while without it the memory grew from 100-200MB in the same amount of time. Neither were interacted with and the tabs were mostly backgrounded.

Steps to reproduce

With deephaven UI (seems to grow faster)

import deephaven.ui as ui
from deephaven.ui import use_state
import deephaven.plot.express as dx

stocks = dx.data.stocks()

@ui.component
def stock_widget_plot(source, default_sym="", default_exchange=""):
    sym, set_sym = use_state(default_sym)
    exchange, set_exchange = use_state(default_exchange)

    ti1 = ui.text_field(
        label="Sym", label_position="side", value=sym, on_change=set_sym
    )
    filters = [f"sym=`{s.strip()}`" for s in sym.upper().split(',')]
    t1 = source.where_one_of(filters)
    p = dx.line(t1, x="timestamp", y="price", by="sym")

    return [t1, p]


swp2 = stock_widget_plot(stocks, "CAT", "TPET")

Without deephaven UI (growth might just be normal data growth)

import deephaven.ui as ui
from deephaven.ui import use_state
import deephaven.plot.express as dx

stocks = dx.data.stocks()

t1 = stocks.where(["sym=`CAT`", 'exchange=`TPET`'])
p = dx.line(t1, x="timestamp", y="price", by="sym")

Additional details and attachments

I saw the issue in both dev and prod environments when using deephaven express. When recording memory allocations, I noticed a particularly high amount of string concatenations ( coming from the handleFigureUpdate call to chartData.update(...) in PlotlyExpressChartModel.ts.

I snapshotted at ~1GB memory usage, over 500MB of that was strings and concatenated strings. There were 18 million concatenated strings in memory.

There are also ~700k SubscriptionDataTable$SubscriptionRow in the snapshot.

Closing the panel eventually freed the memory.

Versions

Engine Version: 0.32.0-SNAPSHOT
Web UI Version: 0.57.1
Java Version: 11.0.21
Barrage Version: 0.6.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingplotly-expressInvolves plotly-express plugin

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions