endo icon indicating copy to clipboard operation
endo copied to clipboard

feat(cache-map): Promote makeLRUCacheMap into a new package

Open gibson042 opened this issue 11 months ago • 2 comments

Description

  • Introduce @endo/cache-map.
  • Remove "LRU" eviction policy constraint (but keep that as the actual current implementation).
  • Support opting in to strongly-held keys (to be used in agoric-sdk for caching string-keyed board mappings).
  • Add a getMetrics() facet for evaluating cache efficiency (currently rudimentary).

Security Considerations

This package sits beneath SES, and so must be defensive without relying upon harden/assert/etc.

Scaling Considerations

The implementation remains a doubly-linked ring with permanent head and LRU eviction policy. All operations are O(1), mutating up to five nodes for promotion/insertion/removal (the target node and its former and new neighbors) but minimizing that when possible (e.g., bailing out early in moveCellAfter when the target is already in the right position). Cells are created up to the specified capacity and never destroyed, although their single-entry weak maps are necessarily replaced when evicting a tail in set. Cells are currently created lazily, although that could be made eager for better memory locality (probably with a boolean lazy option for opting out). All in all, it's probably about as good as an object-based implementation can be (and a bit better than the makeLRUCacheMap from which it is derived).

Documentation Considerations

Includes a README.md with explanation and example usage.

Testing Considerations

Existing tests have been ported and expanded. A future improvement could add GC assertions.

Compatibility Considerations

This continues to support SES, just now as a package that can additionally be used elsewhere.

Upgrade Considerations

None known; this is a new package.

gibson042 avatar May 22 '25 18:05 gibson042

Please change the version number to 1.0.0. When this lands, I can do a one-off publish so Agoric integration CI will continue without interruption.

Done. @kriskowal this should be ready to merge, which I'd like to leave in your hands for that initial publish.

gibson042 avatar May 29 '25 12:05 gibson042

@kriskowal this should again be ready to merge, possibly pending re-review from @boneskull.

gibson042 avatar Jun 06 '25 05:06 gibson042