Added the possibility to memoize proxies in an optimistic way #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This variant adds little code, not much extra logic when
timeoutoption is not used, but it can drastically reduce the amount of roundtrips needed to retrieve (especially repeatedly) same values per proxy, improving performance specially when libraries that access all the time same properties are part of the worker/remote logic.To be considered
gettraps benefit from it, all other traps must invalidate memoized keys (delete, defineProperty, etc)gettrap because it cannot cache properties with accessors but the outcome is less roundtrip, serialization and whatnot ... it might be a win-win or useless, time will telltimeoutoption is used to schedule a cleanup of all cached keys and related values per each proxy. If-1(default) there won't be any cache used at all, if0(suggested) or greater, it dictates for how long properties should be cached.Please note that the cache is a forever growing list of proxies and keys to drop so that passing
Infinity, as example, is a very bad idea, but in general the logic should just work nicely within the current "tick" and all drops and sync delayed after.Performance when no
timeoutis used should not be affected much, it's just anifcondition with no extra or different logic attached (from the previous version).