Skip to content

Commit 74b6650

Browse files
committed
perf(serdes): eager deser Array in place
1 parent 2a7e015 commit 74b6650

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

packages/qwik-router/src/runtime/src/qwik-router-component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import { loadClientData } from './use-endpoint';
7474
import { useQwikRouterEnv } from './use-functions';
7575
import { createLoaderSignal, isSameOrigin, isSamePath, toUrl } from './utils';
7676
import { startViewTransition } from './view-transition';
77-
import transitionCss from './view-transition.css?inline';
77+
import transitionCss from './qwik-view-transition.css?inline';
7878

7979
/**
8080
* @deprecated Use `QWIK_ROUTER_SCROLLER` instead (will be removed in V3)

packages/qwik/src/core/shared/shared-serialization.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ class DeserializationHandler implements ProxyHandler<object> {
175175
*/
176176
export const _eagerDeserializeArray = (
177177
container: DeserializeContainer,
178-
data: unknown[]
178+
data: unknown[],
179+
output: unknown[] = Array(data.length / 2)
179180
): unknown[] => {
180-
const out = Array(data.length / 2);
181181
for (let i = 0; i < data.length; i += 2) {
182-
out[i / 2] = deserializeData(container, data[i] as TypeIds, data[i + 1]);
182+
output[i / 2] = deserializeData(container, data[i] as TypeIds, data[i + 1]);
183183
}
184-
return out;
184+
return output;
185185
};
186186

187187
const resolvers = new WeakMap<Promise<any>, [Function, Function]>();
@@ -196,16 +196,14 @@ const inflate = (
196196
// Already processed
197197
return;
198198
}
199-
// Restore the complex data
200-
if (Array.isArray(data)) {
199+
// Restore the complex data, special case for Array
200+
if (typeId !== TypeIds.Array && Array.isArray(data)) {
201201
data = _eagerDeserializeArray(container, data);
202202
}
203203
switch (typeId) {
204204
case TypeIds.Array:
205-
for (let i = 0; i < (target as any[]).length; i++) {
206-
// read the value to trigger lazy deserialization
207-
(target as any[])[i];
208-
}
205+
// Arrays are special, we need to fill the array in place
206+
_eagerDeserializeArray(container, data as unknown[], target as unknown[]);
209207
break;
210208
case TypeIds.Object:
211209
for (let i = 0; i < (data as any[]).length; i += 2) {
@@ -480,8 +478,7 @@ const allocate = (container: DeserializeContainer, typeId: number, value: unknow
480478
case TypeIds.Constant:
481479
return _constants[value as Constants];
482480
case TypeIds.Array:
483-
// Wrap while inflating so we can handle cyclic references
484-
return wrapDeserializerProxy(container as any, value as any[]);
481+
return Array((value as any[]).length / 2);
485482
case TypeIds.Object:
486483
return {};
487484
case TypeIds.QRL:

0 commit comments

Comments
 (0)