by context switching, but the problem is that if they exit we will just unmap the memory instead of exiting all frames and thereby calling the desturctors
So here's what I want to do: register some stack-allocated objects when they are created, because they need to have a gc visit function, and visit the registered objects during gc.
I'm currently trying to add those objects to a global unordered_map when they get created and remove them when they get destroyed.
But that doesn't work with generators because the destructor might not be called.
And the object will remain in the map and get scanned, which segfaults.
that reminds me of the astinterpreter map we had and besides the performance the other reason why I removed it and replaced it with the "stackmem only" astrinterpreter instances were this problems.
I think what could work is: if a generator gets freed, iterating over your unordered_map and searching if any inststances are inside the memory range of the generator which should get freed
One of the stack objects that I want to scan are rewriter objects. But it seem that the overhead of adding them to a list of objects to scan alone is 1-3% -_-
Hmm let me just make sure that the perf hit does come from the push/popping the rewriter though. Now that I think about it there's a slight chance it comes from somewhere else.
Oh it's not as bad if I move everything into the header file (I guess the compiler then inlines the constructor/destructor?). In that case, the pushing/popping of the rewriter makes a consistent ~0.5% perf hit which is a lot better.