Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CachedRender wrapper #55

Merged
merged 1 commit into from
Jul 30, 2016
Merged

Add CachedRender wrapper #55

merged 1 commit into from
Jul 30, 2016

Conversation

jgaskins
Copy link
Member

This keeps the component from being injected with virtual-DOM logic. It can simply be its own Ruby object. The wrapper acts as an adapter between the two.

There are two main benefits of this:

  • You can now have a @type instance variable. Previously, if you defined one in your component, it would prevent the virtual-DOM engine from caching it.
  • You can define a key method on your component to optimize diffing/patching when child nodes are moved around or deleted. Previously, you either had to wrap the component in a container node with a key property (slower because it would have to be diffed without hints) or set an @key instance variable (completely unintuitive in Ruby).

The downside of this is that it allocates an additional object for each cached component on every render, but I haven't seen this cause any negative effect on realistic performance. Even in my contrived app that renders (among other things) 1000 cached list items, performance improved (from 9ms to 4.5ms per render) with no noticeable difference in memory usage.

Posting a PR in case there's something I may be missing. Render caching is pretty important for Clearwater so I don't want to screw it up. :-)

This keeps the component from being injected with virtual-DOM logic. It
can simply be its own Ruby object. The wrapper acts as an adapter
between the two.
@jgaskins jgaskins force-pushed the cached-render-wrapper branch from 5e3144a to 04ac7ff Compare July 30, 2016 05:17
@jgaskins jgaskins merged commit 44634a3 into master Jul 30, 2016
@jgaskins jgaskins deleted the cached-render-wrapper branch July 30, 2016 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant