Open peterm-canva opened 4 weeks ago
@taj-p PTAL
With this approach, we are retaining the input objects in the cache Map directly. With the previous approach we only kept the string IDs in the cache object. I don't think this is an issue, because the input objects are already retained by the computed()
closure stored in the cache?
@mweststrate PTAL when you have some time, thanks! 🙏
createTransformer()
memoizes object transformations by creating a key for each possible input of typeA
, and then stores a mapping of that key to an object of typeB
in the context variableviews
. The key is stored on eachA
as a non-enumerable property named$transformId
, so that each object can be looked up in theviews
cache later.If we change
views
to be aMap
instead of a plain object, we can get rid of the need for the IDs completely.With this new impl, we still treat string and number inputs by value, and we still treat object inputs by identity. This comes down to the hashing semantics of Map.
This saves a small amount of memory in the unique memo IDs that were created for each input, and also some memory on each input object, which was modified to add the
$transformId
property. This may also have a performance benefit, because we aren't modifying the hidden shape of the inputs any more.