Skip to content

Conversation

@WebReflection
Copy link
Owner

This variant adds little code, not much extra logic when timeout option 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

  • the approach is optimistic: there is no guarantee that if a value is cached is reflected with the same value elsewhere
  • mostly keys and get traps benefit from it, all other traps must invalidate memoized keys (delete, defineProperty, etc)
  • the logic is slower on both local and remote for get trap 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 tell
  • timeout option 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, if 0 (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 timeout is used should not be affected much, it's just an if condition with no extra or different logic attached (from the previous version).

@coveralls
Copy link

coveralls commented Jun 25, 2025

Pull Request Test Coverage Report for Build 15873749662

Details

  • 121 of 121 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.05%) to 99.951%

Totals Coverage Status
Change from base Build 15774551367: -0.05%
Covered Lines: 1651
Relevant Lines: 1651

💛 - Coveralls

@WebReflection WebReflection force-pushed the cached-value-property branch from 610b4bf to 7b0b4d8 Compare June 25, 2025 10:18
@WebReflection WebReflection force-pushed the cached-value-property branch from 7b0b4d8 to f4458ef Compare June 25, 2025 10:19
@WebReflection WebReflection merged commit 86e9b5d into main Jun 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants