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.
<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
| Rule | Reason |
|---|---|
| Re-fetch two bars back | The newest saved bar may have been unfinished, and some feeds treat from as exclusive. |
| A changed closed bar drops the cache | Prices were adjusted (a split, a correction), so the saved copy is wrong. |
| Never save an empty answer | Feeds sometimes return nothing on error. That must not erase good data. |
| Saved in the browser's private file store | It 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.
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.
| Case | Without | With workers |
|---|---|---|
| A live tick (only the last bar changed) | about 0.1 ms | about 0.1 ms |
| Longest page freeze, full recompute: Bollinger Bands | 29 ms | 9 ms |
| Longest page freeze, full recompute: RSI | 21 ms | 14 ms |
| Longest page freeze, full recompute: moving average | 19 ms | 15 ms |
| Longest page freeze, full recompute: EMA | 11 ms | 11 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.