-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Optimising at the AST level #646
Labels
Milestone
Comments
On the function create_main_fragment(component, ctx) {
var p, text_value = ctx.foo ? 'Some large static string...' : 'Or an even bigger one here!', text, current;
return {
[...]
p: function update(changed, ctx) {
if ((changed.foo) && text_value !== (text_value = ctx.foo ? 'Some large static string...' : 'Or an even bigger one here!')) {
setData(text, text_value);
}
}
[...]
};
} |
Yeah, that's unfortunate. I've wondered about having block-level helpers like function create_main_fragment(component, ctx) {
var p, get_text = ctx => ctx.foo ? 'Some large static string...' : 'Or an even bigger one here!', text_value=get_text(ctx), text, current;
return {
// ...
p(changed, ctx) {
if (changed.foo && (text_value !== get_text(ctx)) {
setData(text, text_value);
}
}
};
} In fact those could be hoisted, and potentially even deduplicated across a bundle: const get_text = ctx => ctx.foo ? 'Some large static string...' : 'Or an even bigger one here!';
function create_main_fragment(component, ctx) {
var p, text_value=get_text(ctx), text, current;
return {
// ...
p(changed, ctx) {
if (changed.foo && (text_value !== get_text(ctx)) {
setData(text, text_value);
}
}
};
} |
pngwn
added
compiler
Changes relating to the compiler
temp-stale
and removed
internals
labels
Jun 26, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Second random thought after #645. In cases like this...
...we have to create three blocks (
create_main_fragment
,create_if_block
andcreate_if_block_1
), totalling 74 LOC as of the current version. If we optimised it to the equivalent of this......we get the same result with one block (
create_main_fragment
) totalling 25 LOC, and there's less work to do to update things.There are probably all sorts of optimisations like this we could perform. Might not be straightforward, but definitely worth investigating.
The text was updated successfully, but these errors were encountered: