Skip to content

Some optimisation#92

Merged
Im-Madhur-Gupta merged 2 commits intomainfrom
some-optimisation
Apr 2, 2026
Merged

Some optimisation#92
Im-Madhur-Gupta merged 2 commits intomainfrom
some-optimisation

Conversation

@Camillebzd
Copy link
Copy Markdown
Contributor

  • reduce block state tracker max amount of data to 5k instead of 15k
  • remove useless events 25k array from useEvent and event context

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 1, 2026

Greptile Summary

This PR makes two focused memory-reduction optimisations in the frontend event pipeline: it removes the 25 000-item events state array that was previously kept in EventsContext and returned from useEvents, and it trims the MAX_BLOCKS ring buffer in use-block-state-tracker from 15 000 to 5 000 entries.

Key changes:

  • events-context.tsx — drops events state, MAX_EVENTS_STORED, and the setEvents call; the context now relies exclusively on the existing ref-based subscriber pattern, which is architecturally cleaner and avoids redundant React renders.
  • use-block-state-tracker.tsMAX_BLOCKS reduced from 15 k → 5 k; blocks beyond the cap are already sliced off during BlockStart processing, so behaviour is unchanged except for the lower cap.
  • use-events.tsevents removed from the destructuring and return value; all call sites verified to have no remaining consumers of that field.

No issues found. The removal of the in-memory 25 k array is a meaningful win because it eliminates an O(n) state copy on every WebSocket message, and the subscriber pattern already covers all real consumers.

Confidence Score: 5/5

This PR is safe to merge — changes are well-scoped, all consumers updated, and no remaining references to the removed API.

All three files have straightforward, self-consistent changes. A grep across the frontend confirms zero remaining consumers of the removed events field. The MAX_BLOCKS reduction is a conservative tuning change. No logic bugs, type errors, or broken contracts were found.

No files require special attention.

Important Files Changed

Filename Overview
frontend/contexts/events-context.tsx Removes the 25k-capped events state array and its associated MAX_EVENTS_STORED constant, replacing direct state storage with a pure pub/sub subscriber pattern via refs.
frontend/hooks/use-block-state-tracker.ts Reduces MAX_BLOCKS from 15 000 to 5 000 to lower memory usage of the in-memory block ring buffer.
frontend/hooks/use-events.ts Removes events from the destructured context and the hook's return value to match the now-slimmer EventsContextValue; JSDoc examples updated accordingly.

Sequence Diagram

sequenceDiagram
    participant WS as WebSocket
    participant EP as EventsProvider
    participant UE as useEvents
    participant BST as useBlockStateTracker

    Note over EP: Before: stored up to 25k events in state
    Note over EP: After: pure pub/sub via subscribersRef

    WS->>EP: onmessage (Events[])
    EP->>EP: iterate newEvents
    EP->>UE: subscribersRef callback(evt)
    UE->>BST: onEventRef.current(evt) → queueEvent(evt)
    BST->>BST: applyEventToBlocks() (ring-buffer capped at 5k, was 15k)
Loading

Reviews (1): Last reviewed commit: "reduce block state tracker max amount of..." | Re-trigger Greptile

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 reduces frontend memory and re-render overhead by (1) lowering the retained block history size in the block state tracker and (2) removing the large in-memory events array from the events context/hook API.

Changes:

  • Reduce useBlockStateTracker retained block history from 15,000 to 5,000 blocks.
  • Remove events storage (25k array) from EventsProvider and stop exposing it via useEvents.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
frontend/hooks/use-events.ts Updates the public hook return shape and examples to no longer expose events.
frontend/hooks/use-block-state-tracker.ts Lowers MAX_BLOCKS to reduce retained block history size.
frontend/contexts/events-context.tsx Removes the events state and related retention logic from the context to avoid large in-memory arrays and unnecessary context updates.

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

@Im-Madhur-Gupta Im-Madhur-Gupta merged commit dbdc7d7 into main Apr 2, 2026
8 checks passed
@Im-Madhur-Gupta Im-Madhur-Gupta deleted the some-optimisation branch April 2, 2026 10:09
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