perf: use Set for exclude checks in rest_props, exclude_from_object, legacy_rest_props - #18654
perf: use Set for exclude checks in rest_props, exclude_from_object, legacy_rest_props#18654Xsidz wants to merge 1 commit into
Conversation
…gacy_rest_props Replaces Array.includes() (O(n)) with Set.has() (O(1)) across three sibling paths that were missed when client runes rest_props was updated: - server/index.js:rest_props (called per SSR request) - shared/utils.js:exclude_from_object (called for rest destructuring) - client/reactivity/props.js:legacy_rest_props_handler ($$restProps proxy) No signature changes — arrays are still accepted and converted to Set internally. legacy_rest_props.deleteProperty push() → add() to match. Fixes sveltejs#18601
|
Install the latest version of pnpm add https://pkg.svelte.dev/svelte/c/8103d62b404578f4922e4fb2a8a981673418c831Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: 8103d62 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
dummdidumm
left a comment
There was a problem hiding this comment.
I doubt this will speed up things - it's more likely to slow it down, since this first creates a Set out of the array. A change like this needs to more like #18252 where the compiler was also adjusted to create a hoisted Set. If that is not possible then I think it's better to not do this at all.
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lintFixes #18601
What changed
Three sibling paths were using
Array.includes()(O(n)) for exclude-list membership checks, while the modern client runesrest_propsalready used aSet. This PR brings the remaining paths in line.rest_propspackages/svelte/src/internal/server/index.jsnew Set(rest)at entry,.has()exclude_from_objectpackages/svelte/src/internal/shared/utils.jsnew Set(keys)at entry,.has()legacy_rest_props_handlerpackages/svelte/src/internal/client/reactivity/props.jsnew Set(exclude)at construction,.has()/.add()No signature changes — callers (including the compiler) still pass arrays. Conversion to Set is done internally. The only behavioral difference:
deletePropertyonlegacy_rest_props_handlernow calls.add()instead of.push().Test plan
git diff HEADreviewed — only intended files changed