-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
chore: tweak hydration implementation #11690
Conversation
|
Digging into this PR, it seems we are doing more |
Man, I'm totally flummoxed by this. Firstly, the tests pass locally, I have no idea why they don't in CI. Secondly, this is slower than diff --git a/packages/svelte/src/internal/client/dom/hydration.js b/packages/svelte/src/internal/client/dom/hydration.js
index d51ae78ca..1a7c1bedb 100644
--- a/packages/svelte/src/internal/client/dom/hydration.js
+++ b/packages/svelte/src/internal/client/dom/hydration.js
@@ -40,6 +40,7 @@ export function hydrate_anchor(node) {
/** @type {Comment} */ (node).nextSibling
);
+ var nodes = [];
var current = hydrate_start;
var depth = 0;
@@ -51,6 +52,7 @@ export function hydrate_anchor(node) {
depth += 1;
} else if (data[0] === HYDRATION_END) {
if (depth === 0) {
+ hydrate_start = nodes[0];
return current;
}
@@ -58,6 +60,7 @@ export function hydrate_anchor(node) {
}
}
+ nodes.push(current);
current = /** @type {import('#client').TemplateNode} */ (current.nextSibling);
} ...it speeds up again. This offends reason. |
Dare I say it, do we just do this to get this PR landed? Obviously with comments explaining why. We can then at least compare this to the other PR of yours and see where we go with that. Also it seems your recent tweaks caused the tests to fail? |
Merged #12215 so will close this |
We create an array of nodes when hydration, and attach it to effects as the
dom
property. In non-hydration mode, we turn aDocumentFragment
into an array of nodes.This all creates extra work and allocates extra memory. I was curious as to whether we could speed up hydration by just storing the 'bookends', taking advantage of the fact that the DOM is basically a bunch of linked lists. In this PR there's no more
hydrate_nodes
, justhydrate_start
andhydrate_end
, andeffect.dom
has been replaced byeffect.d1
andeffect.d2
.It seems to be faster in some cases but not all (perhaps because I'm prepending fragments with an empty text node so that
effect.d1
isn't shared between multiple effects, which makes life rather complicated). More investigation needed. I do think the code is a little nicer this way, so I'm hopeful that it can be made faster in all cases.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint