Switch to using WeakMaps for parent pointers
LeaVerou opened this issue · comments
Once we fix #34 the amount of data we hang on the ASTs users provide increases quite a lot, and makes me wonder if we should switch to using a WeakMap
to store these objects, rather than hang them on parent
properties that are observable from userland.
Once we do that, then there’s no downside to just adding/adjusting parent pointers every time we touch an object, since it’s an operation with no side effects and if done right, the perf implications are tiny.
Can anyone thing of any downside with doing this? @adamjanicki2 @DmitrySharabin @karger?
I've never used weakmaps so I need to read the docs, but I support hiding parents from users, especially when we make them more complex in #34, so this seems like a good idea to me
+1 to switching to WeakMap
. AFAIK, we can't iterate over WeakMap
s, and if this is not an issue in our case I can't think of any downside with doing this.
Now that we're using weakmaps, there is no penalty to adding parent pointers at every opportunity (where it wouldn't cause a perf hit), so maybe open an issue about that?
Now that we're using weakmaps, there is no penalty to adding parent pointers at every opportunity (where it wouldn't cause a perf hit), so maybe open an issue about that?
What do you mean by every opportunity?
When other functions are called
From a user standpoint, I think this would be good since it's not going to clog the AST data structure itself, but it will add dependencies/extra code to the other functions within vastly, do we think this is a worthy tradeoff? What are the primary benefits you envision if we call parents from the other relevant functions?