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

fix dirtybit #4095

Merged
merged 5 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/compiler/compile/render_dom/Block.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Renderer from './Renderer';
import Wrapper from './wrappers/shared/Wrapper';
import { b, x } from 'code-red';
import { Node, Identifier, ArrayPattern } from 'estree';
import { Node, Identifier } from 'estree';
import { is_head } from './wrappers/shared/is_head';

export interface BlockOptions {
Expand Down Expand Up @@ -301,12 +301,7 @@ export default class Block {
} else {
const ctx = this.maintain_context ? x`#new_ctx` : x`#ctx`;

let dirty: Identifier | ArrayPattern = { type: 'Identifier', name: '#dirty' };
if (!this.renderer.context_overflow && !this.parent) {
dirty = { type: 'ArrayPattern', elements: [dirty] };
}

properties.update = x`function #update(${ctx}, ${dirty}) {
properties.update = x`function #update(${ctx}, #dirty) {
${this.maintain_context && b`#ctx = ${ctx};`}
${this.chunks.update}
}`;
Expand Down
17 changes: 5 additions & 12 deletions src/compiler/compile/render_dom/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default class Renderer {

context: ContextMember[] = [];
context_lookup: Map<string, ContextMember> = new Map();
context_overflow: boolean;
blocks: Array<Block | Node | Node[]> = [];
readonly: Set<string> = new Set();
meta_bindings: Array<Node | Node[]> = []; // initial values for e.g. window.innerWidth, if there's a <svelte:window> meta tag
Expand Down Expand Up @@ -97,8 +96,6 @@ export default class Renderer {

this.fragment.render(this.block, null, x`#nodes` as Identifier);

this.context_overflow = this.context.length > 31;

this.context.forEach(member => {
const { variable } = member;
if (variable) {
Expand Down Expand Up @@ -240,15 +237,11 @@ export default class Renderer {
return x`${dirty} & /*${names.join(', ')}*/ 0` as BinaryExpression;
}

if (renderer.context_overflow) {
return bitmask
.map((b, i) => ({ b, i }))
.filter(({ b }) => b)
.map(({ b, i }) => x`${dirty}[${i}] & /*${b.names.join(', ')}*/ ${b.n}`)
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`);
}

return x`${dirty} & /*${names.join(', ')}*/ ${bitmask[0].n}` as BinaryExpression;
return bitmask
.map((b, i) => ({ b, i }))
.filter(({ b }) => b)
.map(({ b, i }) => x`${dirty}[${i}] & /*${b.names.join(', ')}*/ ${b.n}`)
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`);
}
} as any;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export default function dom(
}` as ObjectExpression;

let dirty;
if (renderer.context_overflow) {
if (renderer.context.length > 31) {
dirty = x`[]`;
for (let i = 0; i < renderer.context.length; i += 31) {
dirty.elements.push(x`-1`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Let from '../../../nodes/Let';
import { x, p } from 'code-red';
import Block from '../../Block';
import TemplateScope from '../../../nodes/shared/TemplateScope';
import { BinaryExpression } from 'estree';

export function get_slot_definition(block: Block, scope: TemplateScope, lets: Let[]) {
if (lets.length === 0) return { block, scope };
Expand Down Expand Up @@ -36,39 +35,30 @@ export function get_slot_definition(block: Block, scope: TemplateScope, lets: Le
const changes = {
type: 'ParenthesizedExpression',
get expression() {
if (block.renderer.context_overflow) {
const grouped = [];
const grouped = [];

Array.from(names).forEach(name => {
const i = context_lookup.get(name).index.value as number;
const g = Math.floor(i / 31);
Array.from(names).forEach(name => {
const i = context_lookup.get(name).index.value as number;
const g = Math.floor(i / 31);

if (!grouped[g]) grouped[g] = [];
grouped[g].push({ name, n: i % 31 });
});
if (!grouped[g]) grouped[g] = [];
grouped[g].push({ name, n: i % 31 });
});

const elements = [];
const elements = [];

for (let g = 0; g < grouped.length; g += 1) {
elements[g] = grouped[g]
? grouped[g]
.map(({ name, n }) => x`${name} ? ${1 << n} : 0`)
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`)
: x`0`;
}

return {
type: 'ArrayExpression',
elements
};
for (let g = 0; g < grouped.length; g += 1) {
elements[g] = grouped[g]
? grouped[g]
.map(({ name, n }) => x`${name} ? ${1 << n} : 0`)
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`)
: x`0`;
}

return Array.from(names)
.map(name => {
const i = context_lookup.get(name).index.value as number;
return x`${name} ? ${1 << i} : 0`;
})
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`) as BinaryExpression;
return {
type: 'ArrayExpression',
elements
};
}
};

Expand Down
5 changes: 2 additions & 3 deletions src/runtime/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,16 @@ export function get_slot_changes(definition, $$scope, dirty, fn) {
if (definition[2] && fn) {
const lets = definition[2](fn(dirty));

if (typeof $$scope.dirty === 'object') {
if ($$scope.dirty) {
const merged = [];
const len = Math.max($$scope.dirty.length, lets.length);
for (let i = 0; i < len; i += 1) {
merged[i] = $$scope.dirty[i] | lets[i];
}

return merged;
}

return $$scope.dirty | lets;
return lets;
}

return $$scope.dirty;
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/action-custom-event-handler/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function create_fragment(ctx) {
insert(target, button, anchor);
foo_action = foo.call(null, button, /*foo_function*/ ctx[1]) || ({});
},
p(ctx, [dirty]) {
if (is_function(foo_action.update) && dirty & /*bar*/ 1) foo_action.update.call(null, /*foo_function*/ ctx[1]);
p(ctx, dirty) {
if (is_function(foo_action.update) && dirty[0] & /*bar*/ 1) foo_action.update.call(null, /*foo_function*/ ctx[1]);
},
i: noop,
o: noop,
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/bind-open/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function create_fragment(ctx) {
insert(target, details, anchor);
details.open = /*open*/ ctx[0];
},
p(ctx, [dirty]) {
if (dirty & /*open*/ 1) {
p(ctx, dirty) {
if (dirty[0] & /*open*/ 1) {
details.open = /*open*/ ctx[0];
}
},
Expand Down
6 changes: 3 additions & 3 deletions test/js/samples/capture-inject-dev-only/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ function create_fragment(ctx) {
insert(target, input, anchor);
set_input_value(input, /*foo*/ ctx[0]);
},
p(ctx, [dirty]) {
if (dirty & /*foo*/ 1) set_data(t0, /*foo*/ ctx[0]);
p(ctx, dirty) {
if (dirty[0] & /*foo*/ 1) set_data(t0, /*foo*/ ctx[0]);

if (dirty & /*foo*/ 1 && input.value !== /*foo*/ ctx[0]) {
if (dirty[0] & /*foo*/ 1 && input.value !== /*foo*/ ctx[0]) {
set_input_value(input, /*foo*/ ctx[0]);
}
},
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/collapses-text-around-comments/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function create_fragment(ctx) {
insert(target, p, anchor);
append(p, t);
},
p(ctx, [dirty]) {
if (dirty & /*foo*/ 1) set_data(t, /*foo*/ ctx[0]);
p(ctx, dirty) {
if (dirty[0] & /*foo*/ 1) set_data(t, /*foo*/ ctx[0]);
},
i: noop,
o: noop,
Expand Down
6 changes: 3 additions & 3 deletions test/js/samples/component-static-var/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ function create_fragment(ctx) {
set_input_value(input, /*z*/ ctx[0]);
current = true;
},
p(ctx, [dirty]) {
p(ctx, dirty) {
const bar_changes = {};
if (dirty & /*z*/ 1) bar_changes.x = /*z*/ ctx[0];
if (dirty[0] & /*z*/ 1) bar_changes.x = /*z*/ ctx[0];
bar.$set(bar_changes);

if (dirty & /*z*/ 1 && input.value !== /*z*/ ctx[0]) {
if (dirty[0] & /*z*/ 1 && input.value !== /*z*/ ctx[0]) {
set_input_value(input, /*z*/ ctx[0]);
}
},
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/component-store-access-invalidate/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function create_fragment(ctx) {
insert(target, h1, anchor);
append(h1, t);
},
p(ctx, [dirty]) {
if (dirty & /*$foo*/ 1) set_data(t, /*$foo*/ ctx[0]);
p(ctx, dirty) {
if (dirty[0] & /*$foo*/ 1) set_data(t, /*$foo*/ ctx[0]);
},
i: noop,
o: noop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function create_fragment(ctx) {
insert(target, t1, anchor);
insert(target, button, anchor);
},
p(ctx, [dirty]) {
if (dirty & /*$foo*/ 2) set_data(t0, /*$foo*/ ctx[1]);
p(ctx, dirty) {
if (dirty[0] & /*$foo*/ 2) set_data(t0, /*$foo*/ ctx[1]);
},
i: noop,
o: noop,
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/data-attribute/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function create_fragment(ctx) {
insert(target, t, anchor);
insert(target, div1, anchor);
},
p(ctx, [dirty]) {
if (dirty & /*bar*/ 1) {
p(ctx, dirty) {
if (dirty[0] & /*bar*/ 1) {
attr(div1, "data-foo", /*bar*/ ctx[0]);
}
},
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/debug-empty/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function create_fragment(ctx) {
append_dev(h1, t2);
insert_dev(target, t3, anchor);
},
p: function update(ctx, [dirty]) {
if (dirty & /*name*/ 1) set_data_dev(t1, /*name*/ ctx[0]);
p: function update(ctx, dirty) {
if (dirty[0] & /*name*/ 1) set_data_dev(t1, /*name*/ ctx[0]);
debugger;
},
i: noop,
Expand Down
10 changes: 5 additions & 5 deletions test/js/samples/debug-foo-bar-baz-things/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function create_each_block(ctx) {
insert_dev(target, t1, anchor);
},
p: function update(ctx, dirty) {
if (dirty & /*things*/ 1 && t0_value !== (t0_value = /*thing*/ ctx[4].name + "")) set_data_dev(t0, t0_value);
if (dirty[0] & /*things*/ 1 && t0_value !== (t0_value = /*thing*/ ctx[4].name + "")) set_data_dev(t0, t0_value);

if (dirty & /*foo, bar, baz, things*/ 15) {
if (dirty[0] & /*foo, bar, baz, things*/ 15) {
const foo = /*foo*/ ctx[1];
const bar = /*bar*/ ctx[2];
const baz = /*baz*/ ctx[3];
Expand Down Expand Up @@ -119,8 +119,8 @@ function create_fragment(ctx) {
append_dev(p, t1);
append_dev(p, t2);
},
p: function update(ctx, [dirty]) {
if (dirty & /*things*/ 1) {
p: function update(ctx, dirty) {
if (dirty[0] & /*things*/ 1) {
each_value = /*things*/ ctx[0];
let i;

Expand All @@ -143,7 +143,7 @@ function create_fragment(ctx) {
each_blocks.length = each_value.length;
}

if (dirty & /*foo*/ 2) set_data_dev(t2, /*foo*/ ctx[1]);
if (dirty[0] & /*foo*/ 2) set_data_dev(t2, /*foo*/ ctx[1]);
},
i: noop,
o: noop,
Expand Down
10 changes: 5 additions & 5 deletions test/js/samples/debug-foo/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function create_each_block(ctx) {
insert_dev(target, t1, anchor);
},
p: function update(ctx, dirty) {
if (dirty & /*things*/ 1 && t0_value !== (t0_value = /*thing*/ ctx[2].name + "")) set_data_dev(t0, t0_value);
if (dirty[0] & /*things*/ 1 && t0_value !== (t0_value = /*thing*/ ctx[2].name + "")) set_data_dev(t0, t0_value);

if (dirty & /*foo*/ 2) {
if (dirty[0] & /*foo*/ 2) {
const foo = /*foo*/ ctx[1];
console.log({ foo });
debugger;
Expand Down Expand Up @@ -113,8 +113,8 @@ function create_fragment(ctx) {
append_dev(p, t1);
append_dev(p, t2);
},
p: function update(ctx, [dirty]) {
if (dirty & /*things*/ 1) {
p: function update(ctx, dirty) {
if (dirty[0] & /*things*/ 1) {
each_value = /*things*/ ctx[0];
let i;

Expand All @@ -137,7 +137,7 @@ function create_fragment(ctx) {
each_blocks.length = each_value.length;
}

if (dirty & /*foo*/ 2) set_data_dev(t2, /*foo*/ ctx[1]);
if (dirty[0] & /*foo*/ 2) set_data_dev(t2, /*foo*/ ctx[1]);
},
i: noop,
o: noop,
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/debug-hoisted/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function create_fragment(ctx) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
},
m: noop,
p: function update(ctx, [dirty]) {
if (dirty & /*obj, kobzol*/ 3) {
p: function update(ctx, dirty) {
if (dirty[0] & /*obj, kobzol*/ 3) {
const obj = /*obj*/ ctx[0];
const kobzol = /*kobzol*/ ctx[1];
console.log({ obj, kobzol });
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/debug-no-dependencies/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function create_fragment(ctx) {

insert_dev(target, each_1_anchor, anchor);
},
p: function update(ctx, [dirty]) {
p: function update(ctx, dirty) {
if (dirty & /*things*/ 0) {
each_value = things;
let i;
Expand Down
6 changes: 3 additions & 3 deletions test/js/samples/deconflict-builtins/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function create_each_block(ctx) {
append(span, t);
},
p(ctx, dirty) {
if (dirty & /*createElement*/ 1 && t_value !== (t_value = /*node*/ ctx[1] + "")) set_data(t, t_value);
if (dirty[0] & /*createElement*/ 1 && t_value !== (t_value = /*node*/ ctx[1] + "")) set_data(t, t_value);
},
d(detaching) {
if (detaching) detach(span);
Expand Down Expand Up @@ -68,8 +68,8 @@ function create_fragment(ctx) {

insert(target, each_1_anchor, anchor);
},
p(ctx, [dirty]) {
if (dirty & /*createElement*/ 1) {
p(ctx, dirty) {
if (dirty[0] & /*createElement*/ 1) {
each_value = /*createElement*/ ctx[0];
let i;

Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/dev-warning-missing-data-computed/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ function create_fragment(ctx) {
append_dev(p, t1);
append_dev(p, t2);
},
p: function update(ctx, [dirty]) {
if (dirty & /*foo*/ 1 && t0_value !== (t0_value = Math.max(0, /*foo*/ ctx[0]) + "")) set_data_dev(t0, t0_value);
if (dirty & /*bar*/ 2) set_data_dev(t2, /*bar*/ ctx[1]);
p: function update(ctx, dirty) {
if (dirty[0] & /*foo*/ 1 && t0_value !== (t0_value = Math.max(0, /*foo*/ ctx[0]) + "")) set_data_dev(t0, t0_value);
if (dirty[0] & /*bar*/ 2) set_data_dev(t2, /*bar*/ ctx[1]);
},
i: noop,
o: noop,
Expand Down Expand Up @@ -86,7 +86,7 @@ function instance($$self, $$props, $$invalidate) {
};

$$self.$$.update = () => {
if ($$self.$$.dirty & /*foo*/ 1) {
if ($$self.$$.dirty[0] & /*foo*/ 1) {
$: $$invalidate(1, bar = foo * 2);
}
};
Expand Down
Loading