Realโtime applications behave very differently from typical web apps.
A normal React app might fetch data once, store a few dozen items, and never grow beyond that.
A realโtime trading UI is the opposite:
โก Trades stream in continuously
๐ Order books update dozens of times per second
๐ Candles accumulate every minute
๐ฅ๏ธ The app stays open for hours, sometimes entire trading sessions
If you store every update forever, your arrays grow like this:
- 1 minute โ 1,200 updates
- 1 hour โ 72,000 updates
- 4 hours โ 288,000 updates
- 8 hours โ 576,000 updates
And thatโs per currency pair.
Track 10 pairs and youโre easily in the millions of objects.
At that point:
- The browser slows down
- Garbage collection spikes
- Memory usage explodes
- Rendering becomes inconsistent
- AG Grid and charts start choking
- The UI becomes unresponsive
This is why unbounded arrays will kill the browser.
๐ ๏ธ What MemoryโBounded Arrays Actually Do
A memoryโbounded array enforces a hard limit on how many items you keep.
Example:
const MAX_TRADES = 1000
if (trades.length > MAX_TRADES) {
// Immediate memory release
trades.splice(0, trades.length - MAX_TRADES)
}
This means:
- You always keep the latest 1000 trades
- You never store more than 1000
- Memory usage stays predictable
- Rendering cost stays stable
- The app behaves the same after 5 minutes or 5 hours
This is the difference between a realโtime system and a demo app.
โก Why This Keeps the UI Responsive
- Rendering cost stays constant
React, AG Grid, and Highcharts all scale poorly with huge arrays.
Keeping arrays capped means:
- No exponential rendering cost
- No slowdowns over time
- No UI degradation after long sessions
- Memory usage stays flat
Without limits, memory grows forever.
With limits, memory looks like this:
- Start โ 50MB
- 1 hour โ 55MB
- 8 hours โ 60MB
Instead of:
- Start โ 50MB
- 1 hour โ 200MB
- 8 hours โ 1GB+ (browser crash)
- Garbage collection stays predictable
Large arrays create GC spikes that freeze the UI.
Bounded arrays avoid this entirely.
- Charts and grids stay smooth
Highcharts and AG Grid both struggle with large datasets.
Capping arrays ensures:
Smooth scrolling
Fast sorting
Stable FPS
No jank
- The app behaves the same after hours of use
This is the real goal.
A trading UI must be as fast at 4pm as it was at 9am.
Memoryโbounded arrays guarantee that.
๐ The Principle Behind It
Realโtime systems donโt need infinite history โ they need the most recent, relevant data.
Traders care about the last 1000 trades
Order books only need the current snapshot
Charts only need the last N candles
Everything else belongs in a backend database, not the browser.
Memoryโbounded arrays prevent realโtime UIs from degrading over time.
๐ช๐ฟ๐ถ๐๐๐ฒ๐ป ๐ฏ๐ ๐ฅ๐ถ๐ฐ๐ฎ๐ฟ๐ฑ๐ผ ๐ฆ๐ฎ๐๐บ๐ฒ๐๐ต
๐ฆ๐ฒ๐ป๐ถ๐ผ๐ฟ ๐๐ฟ๐ผ๐ป๐โ๐๐ป๐ฑ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ | ๐ฅ๐ฒ๐ฎ๐นโ๐ง๐ถ๐บ๐ฒ ๐จ๐ ๐ฆ๐ฝ๐ฒ๐ฐ๐ถ๐ฎ๐น๐ถ๐๐

Top comments (0)