Skip to content

perf(chart): reduce history candle merge and gap fill work - #736

Merged
kirillDevPro merged 1 commit into
mainfrom
perf/chart-history-merge
Sep 26, 2026
Merged

kirillDevPro merged 1 commit into
mainfrom
perf/chart-history-merge

Conversation

@kirillDevPro

Copy link
Copy Markdown
Collaborator

What & why

Opening a coin, switching timeframe and backfilling history all run merge_bases and
subtract_covered in market/candles.rs over the cached candles.

  • merge_bases inserted every resampled row into a map one at a time. It now appends the
    parts, stable-sorts them on the i64 key and keeps the last row per key, so the same row wins
    as before.
  • subtract_covered rescanned the cover intervals from the start for every hole. It now keeps
    one cover index across the holes, which arrive in ascending order.

The composed series is unchanged. The new tests compare it against a frozen copy of the old
algorithm. CPU preparation drops 23-49% on five
of six cache-state cases (open, timeframe switch and backfill, cache hit and miss); the
timeframe-switch miss was already cheap and is unchanged. The numbers are CPU preparation only,
not I/O or end-to-end latency.

How to verify

  • cargo test -p moon-core --lib market::
  • cargo test -p moon-core --release --lib market::candles::tests::cache_compose_preparation_timing -- --ignored --nocapture prints the before/after medians

Opening a coin, switching timeframe and backfilling history all run
merge_bases and subtract_covered over the cached candles. merge_bases
inserted every resampled row into a map one by one, and
subtract_covered rescanned the cover intervals from the start for
every hole.

merge_bases now appends the parts, stable-sorts them on the i64 key and
keeps the last row per key, so the same row wins as before.
subtract_covered keeps one cover index across holes, which arrive
ascending. The composed series is unchanged; tests compare it against
a frozen copy of the old algorithm. CPU preparation drops 23-49% on
five of six cache-state cases.
@kirillDevPro
kirillDevPro merged commit aa84061 into main Sep 26, 2026
8 checks passed
@kirillDevPro
kirillDevPro deleted the perf/chart-history-merge branch September 26, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant