Aggressive optimisation and protection#95
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR applies several frontend performance optimisations: Two concerns raised in prior review threads remain open: the queue cap silently drops the newest events (leaving block-state transitions permanently missing after overflow), and the label-cache guard nukes the entire cache rather than evicting selectively (causing a visible label flash on re-fetch). Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant BE as Backend Events
participant QE as queueEvent
participant Q as eventQueueRef
participant SI as setInterval
participant ST as setBlocks
participant UI as React UI
BE->>QE: event arrives
alt slow motion active
QE->>Q: "push if length < MAX_QUEUE_SIZE"
note over Q: overflow silently drops newest events
SI->>Q: shift chunk up to N BlockStart events
SI->>ST: onFlushEvents(chunk)
else normal mode
QE->>ST: onProcessEvent(event)
end
ST->>ST: findIndex + slice() targeted update
ST->>UI: new blocks array shallow copy
note over UI: trimmed to 200 blocks max
Reviews (2): Last reviewed commit: "lint" | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
This PR focuses on reducing memory/CPU overhead in the blockchain trackers and related hooks by limiting retained history, avoiding heavier array operations in hot paths, and preventing unbounded buffering.
Changes:
- Reduced retained block history size in both block trackers.
- Added a maximum bound to the slow-motion event queue.
- Adjusted scroll-to-end behavior to avoid stale
sortedBlocks.lengthin rAF callbacks. - Added a cache-size cap mechanism for contract labels.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
frontend/hooks/use-contract-labels.ts |
Adds a cache cap for resolved contract labels/addresses. |
frontend/hooks/use-blockchain-slow-motion.ts |
Adds a max size limit to the slow-motion event queue. |
frontend/hooks/use-blockchain-scroll.ts |
Uses a ref to avoid rAF closures reading stale block list lengths. |
frontend/hooks/use-block-state-tracker.ts |
Reduces max tracked blocks and optimizes state updates to avoid full map(). |
frontend/hooks/use-block-execution-tracker.ts |
Reduces max tracked blocks and optimizes updates to avoid rebuilding large arrays. |
Comments suppressed due to low confidence (1)
frontend/hooks/use-block-execution-tracker.ts:53
handleEventis memoized with an empty dependency list but closes overreplaceLastBlock/replaceBlockAt, which are re-created each render. With eslint-config-next this typically triggersreact-hooks/exhaustive-deps, and it also makes the callback’s captured helpers implicitly “frozen” to the initial render. Consider moving these helpers to module scope (pure functions) or memoizing them and including them in the dependency array.
// Handle real-time events from the backend
const handleEvent = useCallback((event: SerializableEventData) => {
switch (event.payload.type) {
case 'BlockStart': {
const payload = event.payload
const blockNumber = event.block_number || payload.block_number
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@greptile-apps, I updated the description rereview |
Uh oh!
There was an error while loading. Please reload this page.