2021-12-11
Functional GUI programming style such as in React generates lot's of garbage memory because a new managed memory data structure called "virtual DOM" ⬀ (VDOM) is generated for each frame to describe the ui appearance. This may not be a problem if the ui updates only few times a second based on user keyboard or mouse button input, but it may become a bottleneck if such programming style is used to define animations or for visualizing mouse movement for example in a drag and drop scenario. In web browsers animations are handled by CSS and javascript is not run on every frame so no garbage memory is generated.
Region-based memory management ⬀ could possibly be used to efficiently collect garbage memory generated by functional GUI programming. The VDOM could be written to a memory "arena" that could be overriden on the next frame after the GPU state has bee updated based on it.
Each component could have it's own arena so that if the component does not update it's appearance, the part of the VDOM corresponding to the component is kept intact.
If there is shared memory available between CPU and GPU the VDOM could be written there in a format directly usable by GPU shaders.
This site is generated with zetgen