perf: add native hydrate wasm path

This commit is contained in:
Youzini-afk
2026-04-22 20:08:03 +08:00
parent 5c20417ce4
commit 4ab2e0c3c9
13 changed files with 892 additions and 10 deletions

View File

@@ -69,6 +69,10 @@ async function loadFromWasmPackArtifacts() {
return {
solve_layout: module.solve_layout,
build_hydrate_records:
typeof module.build_hydrate_records === "function"
? module.build_hydrate_records
: null,
build_persist_delta_compact_hash:
typeof module.build_persist_delta_compact_hash === "function"
? module.build_persist_delta_compact_hash
@@ -222,6 +226,26 @@ export async function installNativePersistDeltaHook() {
return getNativeModuleStatus();
}
export async function installNativeHydrateHook() {
const module = await loadNativeModule({
forceRetry: shouldRetryNativeLoad(),
});
if (!module || typeof module.build_hydrate_records !== "function") {
throw new Error("native hydrate builder unavailable");
}
globalThis.__stBmeNativeHydrateSnapshotRecords = (snapshotView = {}, options = {}) => {
const raw = module.build_hydrate_records({
nodes: Array.isArray(snapshotView?.nodes) ? snapshotView.nodes : [],
edges: Array.isArray(snapshotView?.edges) ? snapshotView.edges : [],
recordsNormalized: options?.recordsNormalized === true,
});
return raw && typeof raw === "object" ? raw : null;
};
return getNativeModuleStatus();
}
export function getNativeModuleStatus() {
return {
loaded: Boolean(cachedNativeModule),