Docs

Speed and offline

Two optional features, both off by default. The history cache makes reloads fetch less and keeps a chart usable offline. Indicator workers keep a chart with a very long history smooth.

History cache

Turn it on with one prop. The chart then remembers the bars it loaded, in the browser, for each symbol and timeframe.

tsx
<AstroneumChart historyCache /* or historyCache={{ namespace: 'my-feed', maxBars: 20000 }} */ />

See it work

This chart has the cache on. The panel shows how many bars each load asked the datafeed for, and what is saved. Reload the page and compare: the second load fetches a handful of bars instead of the whole window.

How much did this load ask for?

This load
waiting…
The load before
none yet: reload the page

Saved in this browser

Nothing saved yet. It appears a moment after the chart loads.

    Try it: reload and compare. With bars saved, the second load asks the datafeed for only the newest few instead of the whole window.

    How it decides what to fetch

    RuleReason
    Re-fetch two bars backThe newest saved bar may have been unfinished, and some feeds treat from as exclusive.
    A changed closed bar drops the cachePrices were adjusted (a split, a correction), so the saved copy is wrong.
    Never save an empty answerFeeds sometimes return nothing on error. That must not erase good data.
    Saved in the browser's private file storeIt works offline and needs no server. Browsers that cannot write there simply skip the cache.

    Indicator workers

    With tens of thousands of bars, recalculating an indicator takes long enough to make scrolling stutter. For the six built-in indicators with step kernels (MA, EMA, RSI, BOLL, VOL, MACD) a live tick always takes a shortcut that only recomputes the newest bar; workers move the remaining heavy part, the full recompute on a first load or a new symbol, off the page's main thread.

    tsx
    import { configureIndicatorWorkers } from 'astroneum'
    
    // Applies to every chart on the page. MA, EMA, RSI, BOLL, VOL and MACD, on 20,000+ bars.
    configureIndicatorWorkers({ enabled: true })

    What it buys

    Measured in Chrome on a laptop with 200,000 one-minute bars. Your numbers will differ, but the shape holds.

    CaseWithoutWith workers
    A live tick (only the last bar changed)about 0.1 msabout 0.1 ms
    Longest page freeze, full recompute: Bollinger Bands29 ms9 ms
    Longest page freeze, full recompute: RSI21 ms14 ms
    Longest page freeze, full recompute: moving average19 ms15 ms
    Longest page freeze, full recompute: EMA11 ms11 ms

    Full recomputes gain less than you might expect because turning the numbers into chart rows still happens on the page; EMA gains least for that reason. The results are identical either way: a test compares them bar for bar.