Better gc control #516
KaruroChori
started this conversation in
Ideas
Replies: 1 comment 4 replies
-
Hey there! Part of this discussion needs to happen on QuickJS-ng too, specifically the extra hooks, but there are improvements we can do today. Exposing a form of const gc = {
run : ()=>void,
setEnabled : (value:boolean)=>void,
setThreshold : (value:number)=>void,
} There is certain overlap between enabled and threshold, but I think separating the 2 makes sense. As for your proposal:
What's the difference between these 2?
What's the difference between this and
These hooks make sense to ma, but we need to discuss that in QuickJS. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My last proposal for now.
Everything else it way too specific for my application and would not beneficial to anyone else.
Summary
To expand the current support of the underlying garbage collection mechanism in txiki.
To expose the interface needed for a finer control already enabled by quickjs, and to extend it with some additional hooks.
Rationale
One of the distinguishing features of quickjs compared to other engines is its reliance on a reference counting mechanism to handle the lifetime of all the object without cyclic dependencies. Otherwise, a more traditional garbage collector is employed, but the approach is to give ample freedom to the developer about when and how it should run. This might well be never, or based on fixed/dynamic thresholds.
As a result, we can either try to design code which avoids cyclic references to have a fully deterministic runtime execution in critical parts and perform manual gc events only in safe regions, or keep it mostly deterministic, with rare gc events to handle on a case by case basis. This makes quickjs particularly suitable for a wide range of real-time applications on embedded systems as long as the formal requirements are not too strict.
It would be nice if txiki would expose the underlying GC logic and events via callbacks, so that we can tune the thresholds and run custom code before and after any of those events is triggered. For example, if I am controlling a system which can be paused in a safe state, I might want to do that, perform the GC routine and resume the execution right after.
Proposed interface
Something like this, replacing the current
gc
function.While running one of those callbacks no further GC events should be considered.
Beta Was this translation helpful? Give feedback.
All reactions