Skip to content

drop the data instead of rolling it out#93

Merged
Im-Madhur-Gupta merged 2 commits intomainfrom
drop-data-instead-of-rolling-out
Apr 2, 2026
Merged

drop the data instead of rolling it out#93
Im-Madhur-Gupta merged 2 commits intomainfrom
drop-data-instead-of-rolling-out

Conversation

@Camillebzd
Copy link
Copy Markdown
Contributor

Motivation:

Explain here the context, and why you're making that change. What is the problem you're trying to solve.

Modifications:

Describe the modifications you've done.

Result:

After your change, what will change.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts how the frontend retains live event history (swaps, transfers, and block tracking) by switching from a strict rolling window to a “trim in chunks” approach to reduce state growth and update churn.

Changes:

  • Trim swaps/transfers lists only when exceeding their thresholds, and when trimming occurs keep only ~1/3 of the threshold.
  • Reduce useBlockStateTracker’s MAX_BLOCKS from 15000 to 5000 and apply the same chunk-trim strategy.
  • Apply the same chunk-trim strategy to useBlockExecutionTracker’s block list.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
frontend/hooks/use-transfer-events.ts Changes transfer history retention to chunk-trim when exceeding MAX_TRANSFERS.
frontend/hooks/use-swap-events.ts Changes swap history retention to chunk-trim when exceeding MAX_SWAPS.
frontend/hooks/use-block-state-tracker.ts Lowers block retention threshold and chunk-trims block list on overflow.
frontend/hooks/use-block-execution-tracker.ts Chunk-trims tracked blocks on overflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 1, 2026

Greptile Summary

This PR replaces the per-item rolling-window strategy (always keep exactly the last N items) with a drop-to-1/3 on overflow strategy across four event-tracking hooks. When an array exceeds its MAX_* threshold, it is immediately truncated to Math.ceil(MAX / 3) items (retaining the newest). MAX_BLOCKS in use-block-state-tracker.ts is also reduced from 15 000 → 5 000, aligning it with the other hooks.

Key changes:

  • use-block-execution-tracker.ts — overflow guard added in BlockStart case; keeps newest ~1 667 blocks after drop.
  • use-block-state-tracker.ts — same guard in applyEventToBlocks; capacity reduced 3×.
  • use-swap-events.ts — swaps prepended (newest-first), truncation uses slice(0, N) to keep newest.
  • use-transfer-events.ts — identical pattern to swaps; cumulativeTransferred remains an all-time session total and does not reset on truncation (pre-existing design, previously noted).

The slice directions are consistent: block hooks append to the tail and truncate with .slice(-N); swap/transfer hooks prepend to the head and truncate with .slice(0, N). No custom rules are violated by these changes.

Confidence Score: 5/5

Safe to merge — no correctness or data-integrity regressions introduced; all truncation directions are consistent with each array's ordering.

No P0 or P1 issues found. The truncation logic is correct and symmetric across all four hooks (block hooks append+slice-tail, event hooks prepend+slice-head). The one previously flagged concern (cumulativeTransferred diverging from visible transfers) is a pre-existing design choice that was already discussed. All remaining observations are P2 style/documentation suggestions.

No files require special attention.

Important Files Changed

Filename Overview
frontend/hooks/use-block-execution-tracker.ts Switches from a rolling-window slice to drop-to-1/3 on overflow; MAX_BLOCKS remains 5000, truncation correctly keeps the newest blocks via .slice(-Math.ceil(MAX_BLOCKS/3)).
frontend/hooks/use-block-state-tracker.ts MAX_BLOCKS reduced from 15000 → 5000; same drop-to-1/3 strategy applied in applyEventToBlocks. Works correctly with both the single-event path and the flushEvents reduce loop.
frontend/hooks/use-swap-events.ts Swaps are prepended (newest-first), so truncation correctly uses .slice(0, Math.ceil(MAX_SWAPS/3)) to retain the newest entries after overflow.
frontend/hooks/use-transfer-events.ts Same drop-to-1/3 strategy as swaps; cumulativeTransferred continues to accumulate unconditionally regardless of truncation (pre-existing design, previously flagged).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[New event arrives] --> B[Prepend / Append item to array]
    B --> C{length > MAX?}
    C -- No --> D[Return full array as-is]
    C -- Yes --> E[Drop ~2/3 of data, keep newest Math.ceil(MAX/3) items]
    E --> F[Array shrinks to ~1/3 capacity]
    F --> D
    D --> G[React state update]

    subgraph "Block hooks — append newest at end"
        H[".slice(-Math.ceil(MAX/3))"]
    end
    subgraph "Swap & Transfer hooks — prepend newest at front"
        I[".slice(0, Math.ceil(MAX/3))"]
    end
    E --> H
    E --> I
Loading

Reviews (2): Last reviewed commit: "drop the data instead of rolling it out" | Re-trigger Greptile

@Im-Madhur-Gupta Im-Madhur-Gupta marked this pull request as draft April 2, 2026 10:00
@Im-Madhur-Gupta Im-Madhur-Gupta marked this pull request as ready for review April 2, 2026 10:00
@Im-Madhur-Gupta Im-Madhur-Gupta merged commit d4c2015 into main Apr 2, 2026
3 checks passed
@Im-Madhur-Gupta Im-Madhur-Gupta deleted the drop-data-instead-of-rolling-out branch April 2, 2026 10:11
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.

4 participants