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

First pass at tracking mutation to avoid unnecessary update code - #1952 #1980

Merged
merged 1 commit into from
Jan 13, 2019

Conversation

evs-chris
Copy link
Contributor

Also tracks mutation on child refs of const declarations - #1917

This is my swing at tracking what references are actually mutated to avoid generating unnecessary update code where no mutation can occur. It does so by adding mutation tracking to the TemplateScope and an additional walk through the main script instance of a component. To start, only mustaches and attributes will check their dependencies for mutations and skip the update code if they don't look like they change.

This does not attempt the stretch goal of hoisting non-mutating refs up out of the contextual chunk of the component because my initial naive attempt blew up the world. It turns out it's not as simple as just adjusting the hoist for consts to include lets and moving it to after the template is processed 😄.

This also adds a check on the dependency tracking for expressions that will skip the const check if the reference happens to include more than the base member (or at least I think it does, I'm still a little fuzzy on how scoping and references are handled, but I'm getting there).

There's already a TODO regarding how many times the js is walked, and this adds yet another pass through that could probably be combined with at least one of the others. It may make sense to have all the walking methods return an object of listeners for a walk with closures set up for their internal state and then run a single walk at the end that fires said closures as it goes. I didn't look at it very hard, but I promise I feel bad about adding yet another pass.

@Rich-Harris Rich-Harris merged commit 4c9a55c into sveltejs:master Jan 13, 2019
@Rich-Harris
Copy link
Member

This is awesome, thank you!

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.

2 participants