You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
normalizeChildren: preallocate array length and perform key-consistency checks after normalization
This change preallocates the array to the input length and collapses multiple loops into a single pass. Assigning immediately after preallocation improves performance on V8 (generally neutral elsewhere).
Key checks are now performed on normalized vnodes, making the consistency validation more accurate and clarifying the correspondence between error messages and code.
Perf-sensitive comments have been clarified to reflect the original intent of commit 6c562d2.
Behavior is unchanged, except that the timing/order of related errors may differ slightly. All existing tests pass.
Additionally, bundle size is slightly reduced.
? "In fragments, vnodes must either all have keys or none have keys. You may wish to consider using an explicit keyed empty fragment, m.fragment({key: ...}), instead of a hole."
24
-
: "In fragments, vnodes must either all have keys or none have keys."
25
-
)
26
-
}
27
-
}
28
-
for(vari=0;i<input.length;i++){
29
-
children[i]=Vnode.normalize(input[i])
30
-
}
13
+
// Preallocate the array length (initially holey) and fill every index immediately in order.
14
+
// Benchmarking shows better performance on V8.
15
+
varchildren=newArray(input.length)
16
+
// Count the number of keyed normalized vnodes for consistency check.
17
+
// Note: this is a perf-sensitive check.
18
+
// Fun fact: merging the loop like this is somehow faster than splitting
? "In fragments, vnodes must either all have keys or none have keys. You may wish to consider using an explicit keyed empty fragment, m.fragment({key: ...}), instead of a hole."
28
+
: "In fragments, vnodes must either all have keys or none have keys."
0 commit comments