fix(plugin): prevent UI freeze from rapid high-frequency data clones - #96
fix(plugin): prevent UI freeze from rapid high-frequency data clones#96Utkarshpandey0001 wants to merge 1 commit into
Conversation
2778d56 to
cdd733c
Compare
|
@illume Hi, issue of ui freezing because of brute approach by storing data in array has been optimized to its max. Ui was redering smoothly over my local machine. Let me know your review and if any suggestion for further improvement. Thank u. |
0debbf3 to
64f0a7f
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses UI freezes caused by high-frequency gadget streams by batching incoming gadget payload processing and reducing how often large arrays are cloned/updated in React state.
Changes:
- Introduces
GadgetDataBufferto queue gadget payloads and flush updates on a 300ms timer. - Updates
processGadgetData/createGadgetCallbacksand resource gadget handling to use the buffer and flush on completion/cleanup. - Adds
// @ts-nocheckto several UI modules (disabling TypeScript checks in those files).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| src/gadgets/utility.tsx | Adds the batching buffer and routes gadget data processing through it. |
| src/gadgets/resourcegadgets.tsx | Uses the new buffer for onData handling and flushes during cleanup. |
| src/gadgets/params/sortingfilter.tsx | Disables TS checking via // @ts-nocheck. |
| src/gadgets/params/filter.tsx | Disables TS checking via // @ts-nocheck. |
| src/gadgets/params/annotation.tsx | Disables TS checking via // @ts-nocheck. |
| src/gadgets/gadgetGrid.tsx | Disables TS checking via // @ts-nocheck. |
| src/common/GadgetWithDataSource/index.tsx | Disables TS checking via // @ts-nocheck. |
| src/common/GadgetDescription/index.tsx | Disables TS checking via // @ts-nocheck. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This commit addresses the issue where running high-frequency gadgets caused the React UI to become unresponsive by blocking the main thread natively. - Modifies `processGadgetData` to accept a batching `GadgetDataBuffer` instance. - Implements `GadgetDataBuffer` with a `setTimeout` loop designed to aggregate and flush `massagedData` payloads every 300ms organically, rather than rapidly cloning a 20,000 item array 100+ times per second natively. - Updates `createGadgetCallbacks` and `resourcegadgets.tsx` to utilize the new buffer. Signed-off-by: Utkarshpandey0001 <rajutkarshpandey2003@gmail.com>
64f0a7f to
39a8247
Compare
|
Hi @ashu8912 , i did change the files suggested by copilot so there were basically ts-checks to escape type check now i did correct import to resolve those ts types isssues . All tests , type checks and lints passes perfectly . Could you pls check and review it one more time |
fixes #89
This commit addresses the issue where running high-frequency gadgets caused the React UI to become unresponsive by blocking the main thread natively.
setTimeoutloop designed to aggregate and flushmassagedDatapayloads every 300ms organically, rather than rapidly cloning a 20,000 item array 100+ times per second natively.Title: fix: implement throttled memory buffer to prevent UI freezes on high-frequency gadgets
This pull request resolves a critical performance bottleneck where high-frequency gadget streams (such as
trace tcporprofile cpu) would cause the Headlamp UI to severely lag or freeze completely.Previously, the plugin processed every incoming WebSocket event by synchronously cloning and slicing arrays up to 20,000 items in length inside a React state setter (
[...prevData, massagedData]). When handling hundreds of events per second, this constant array re-allocation overloaded the JavaScript main thread and forced heavy garbage collection loops.To safely mitigate this, a GadgetDataBuffer class has been introduced to temporarily queue incoming events in an asynchronous map. The queue is flushed to the main React state precisely once every 300ms, effectively batching modifications and vastly increasing frame stability without dropping any gadget payloads.
How to use
inspektor-gadgetplugin compiled and installed.trace tcporprofile cpu.Testing done
Executed local UI verification against an active Minikube cluster and confirmed that rendering performance stabilized securely while running heavy trace gadgets for several minutes.
Validated the codebase strictly natively against Headlamp's compiler and linter requirements: