Skip to content

Improved Caching Performance

Compare
Choose a tag to compare
@UselessPickles UselessPickles released this 24 Feb 05:03
· 113 commits to master since this release

Improvements

  • A WeakMap is now instead of a Map to cache EnumWrapper instances. This ensures that EnumWrapper instances are garbage collected whenever their corresponding "enum-like" objects are garbage collected (no memory leaks). This should also improve cache set/get performance because WeakMap implementations can feature O(1) constant time set/get.
  • The $enum() function was also optimized by making it a direct alias/reference to EnumWrapper.getCachedInstance().

Breaking Changes

Because WeakMap solves the concern about memory leaks when ts-enum-util is used on temporary enum-like objects, there's really no need to opt out of caching any more. Accordingly, the following API changes were made:

  • Removed EnumWrapper.createUncachedInstance()
  • Removed optional useCache param to the $enum() function (it now always uses the cache).