Don't touch the DOM unless a style has actually changed #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that when using a spade defattr on an item within a
virtualized list, scroll performance got a bit janky. Other virtualized
list components performed just fine, so I dove into the profiler to see
what was going on.
It turns out that each call to the defattr function was touching the
dom, even though its params weren't changed. The reason I wasn't running
into this with other virtualized lists was that they were styling their
children at a higher level, so the function was only called once.
So, this change will only touch the dom if the underlying style has
actually changed. Since Spade encourages small styles, this comparison
should be fast enough---and certainly faster than updating the DOM---but
if anyone discovers performance issues we might be able to assume that
in production, any given style function, when provided the same
parameters, will always produce the same CSS, and thus skip updates
entirely in production, while keeping the current behavior for testing
styles with hot reload in dev mode.