Skip to content

chore: more signal fine-tuning #9531

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

Merged
merged 8 commits into from
Nov 18, 2023
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
5 changes: 5 additions & 0 deletions .changeset/hungry-dots-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: more signal perf tuning
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ export const global_visitors = {
},
MemberExpression(node, { state, next }) {
if (node.object.type === 'ThisExpression') {
// rewrite `this.#foo` as `this.#foo.value` inside a constructor
// rewrite `this.#foo` as `this.#foo.v` inside a constructor
if (node.property.type === 'PrivateIdentifier') {
const field = state.private_state.get(node.property.name);

if (field) {
return state.in_constructor ? b.member(node, b.id('value')) : b.call('$.get', node);
return state.in_constructor ? b.member(node, b.id('v')) : b.call('$.get', node);
}
}

// rewrite `this.foo` as `this.#foo.value` inside a constructor
// rewrite `this.foo` as `this.#foo.v` inside a constructor
if (node.property.type === 'Identifier' && !node.computed) {
const field = state.public_state.get(node.property.name);

if (field && state.in_constructor) {
return b.member(b.member(b.this, field.id), b.id('value'));
return b.member(b.member(b.this, field.id), b.id('v'));
}
}
}
Expand Down
15 changes: 5 additions & 10 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
EACH_IS_CONTROLLED,
EACH_INDEX_REACTIVE,
EACH_ITEM_REACTIVE,
EACH_IS_ANIMATED,
PassiveDelegatedEvents,
DelegatedEvents
} from '../../constants.js';
Expand Down Expand Up @@ -624,7 +623,7 @@ export function bind_playback_rate(media, get_value, update) {
// Needs to happen after the element is inserted into the dom, else playback will be set back to 1 by the browser.
// For hydration we could do it immediately but the additional code is not worth the lost microtask.

/** @type {import('./types.js').Signal | undefined} */
/** @type {import('./types.js').ComputationSignal | undefined} */
let render;
let destroyed = false;
const effect = managed_effect(() => {
Expand Down Expand Up @@ -2083,7 +2082,7 @@ export function update_each_item_block(block, item, index, type) {
if (transitions !== null && (type & EACH_KEYED) !== 0) {
let prev_index = block.index;
if (index_is_reactive) {
prev_index = /** @type {import('./types.js').Signal<number>} */ (prev_index).value;
prev_index = /** @type {import('./types.js').Signal<number>} */ (prev_index).v;
}
const items = block.parent.items;
if (prev_index !== index && /** @type {number} */ (index) < items.length) {
Expand Down Expand Up @@ -2125,7 +2124,7 @@ export function destroy_each_item_block(
if (!controlled && dom !== null) {
remove(dom);
}
destroy_signal(/** @type {import('./types.js').Signal} */ (block.effect));
destroy_signal(/** @type {import('./types.js').EffectSignal} */ (block.effect));
}
}

Expand Down Expand Up @@ -2244,11 +2243,7 @@ function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, re
? []
: Array.from(maybe_array);
if (key_fn !== null) {
const length = array.length;
keys = Array(length);
for (let i = 0; i < length; i++) {
keys[i] = key_fn(array[i]);
}
keys = array.map(key_fn);
}
if (fallback_fn !== null) {
if (array.length === 0) {
Expand Down Expand Up @@ -3163,7 +3158,7 @@ export function mount(component, options) {
if (hydration_fragment !== null) {
remove(hydration_fragment);
}
destroy_signal(/** @type {import('./types.js').Signal} */ (block.effect));
destroy_signal(/** @type {import('./types.js').EffectSignal} */ (block.effect));
}
];
}
Expand Down
Loading