Blueprint icon indicating copy to clipboard operation
Blueprint copied to clipboard

[WIP DNR] Element caching

Open kdaker opened this issue 3 years ago • 0 comments

This is a proposal to implement caching for element sizes across renders. This is very much a prototype and incomplete however it does build.

The main idea is we make Element require a hashing method func hash(into hasher: inout Hasher) similar to Hashable. (We don't implement Hashable directly to avoid needing to type-erase Element).

We provide a default implementation that just hashes a generated UUID, this means the hash always changes and makes it equivalent to the 'old world'. We then can implement hash(into:) on elements that can benefit from it gradually.

We then use this hash as a key for our cache.

The current expectation of hash implementation is to hash nested elements. For example a Column would include the hash of it's children. This is inefficient given it is recursive.

The next step I wanted to do is to create a hash of the path of the element in the tree (ex: hash of "column.1.row.1.tappable.label") and combine that with the hash of the element to produce a unique key/id for our cache. The hash of the element would not include children in this case, only element properties and thus run in O(1).

Furthermore, the nodes of the Element tree have references to their parents to allow us to invalidate the entire chain up to the root quickly if needed.

kdaker avatar Sep 02 '22 22:09 kdaker