-
-
Notifications
You must be signed in to change notification settings - Fork 202
perf: Implement Adaptive Backpressure for VDOM Updates via Pre-Update Hooks #8996
Copy link
Copy link
Closed
Labels
aicoreCore framework functionalityCore framework functionalityenhancementNew feature or requestNew feature or requestperformancePerformance improvements and optimizationsPerformance improvements and optimizations
Description
Context
In high-frequency update scenarios (e.g., Grid scrolling), ScrollManager currently uses a fixed throttle (e.g., 48ms) to prevent flooding the VDOM worker with updates the Main Thread cannot consume fast enough ("Death Spiral").
While effective, a fixed timer is not adaptive. It caps performance on high-end devices (which could handle >20fps) and might still be too aggressive for very low-end devices.
The Goal
Implement Adaptive Backpressure where the producer (ScrollManager) automatically scales its update rate based on the consumer's (Main Thread) capacity.
The Mechanism
- Backpressure Check: The producer checks
component.isVdomUpdating. - Opt-Out: If
true, the producer skips the heavy calculation (e.g.,createViewData) and registers a Pre-Update Hook. - Re-Entry: When the component finishes its current update (
resolveVdomUpdate), it executes the registered Pre-Update Hook before checkingneedsVdomUpdatefor the next cycle.
Proposed Changes
-
src/manager/VDomUpdate.mjs:- Add
preUpdateCallbackMap(Map<String, Function[]>). - Implement
registerPreUpdate(ownerId, callback). - Implement
executePreUpdates(ownerId): Executes callbacks and clears the list.
- Add
-
src/mixin/VdomLifecycle.mjs:- Update
resolveVdomUpdate:// ... existing logic ... VDomUpdate.unregisterInFlightUpdate(me.id); VDomUpdate.triggerPostUpdates(me.id); // NEW: Execute Pre-Update Hooks (e.g. re-run createViewData) VDomUpdate.executePreUpdates(me.id); if (me.needsVdomUpdate) { me.update(); }
- Update
-
Usage (Example):
// ScrollManager.mjs if (gridBody.isVdomUpdating) { // Queue the work for immediately after the current frame clears Neo.manager.VDomUpdate.registerPreUpdate(gridBody.id, () => { // This sets needsVdomUpdate = true internally gridBody.createViewData(); }); return; }
Benefits
- Zero Latency: No fixed timers. Updates happen as fast as the hardware allows.
- Stability: Impossible to flood the queue, as new work is only scheduled when the previous work completes.
- Efficiency: Skips redundant calculations during blocked periods.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
aicoreCore framework functionalityCore framework functionalityenhancementNew feature or requestNew feature or requestperformancePerformance improvements and optimizationsPerformance improvements and optimizations