perf: add dirty persist and hydrate/layout optimizations

This commit is contained in:
Youzini-afk
2026-04-22 22:27:22 +08:00
parent 0b71a35a93
commit fb4dabeaf1
11 changed files with 1297 additions and 184 deletions

View File

@@ -73,6 +73,10 @@ async function loadFromWasmPackArtifacts() {
typeof module.build_hydrate_records === "function"
? module.build_hydrate_records
: null,
build_hydrate_records_compact:
typeof module.build_hydrate_records_compact === "function"
? module.build_hydrate_records_compact
: null,
build_persist_delta_compact_hash:
typeof module.build_persist_delta_compact_hash === "function"
? module.build_persist_delta_compact_hash
@@ -230,16 +234,26 @@ export async function installNativeHydrateHook() {
const module = await loadNativeModule({
forceRetry: shouldRetryNativeLoad(),
});
if (!module || typeof module.build_hydrate_records !== "function") {
if (
!module ||
(typeof module.build_hydrate_records !== "function" &&
typeof module.build_hydrate_records_compact !== "function")
) {
throw new Error("native hydrate builder unavailable");
}
globalThis.__stBmeNativeHydrateSnapshotRecords = (snapshotView = {}, options = {}) => {
const raw = module.build_hydrate_records({
const hydratePayload = {
nodes: Array.isArray(snapshotView?.nodes) ? snapshotView.nodes : [],
edges: Array.isArray(snapshotView?.edges) ? snapshotView.edges : [],
recordsNormalized: options?.recordsNormalized === true,
});
preferCompactResult: options?.preferCompactResult !== false,
};
const raw =
typeof module.build_hydrate_records_compact === "function" &&
options?.preferCompactResult !== false
? module.build_hydrate_records_compact(hydratePayload)
: module.build_hydrate_records(hydratePayload);
return raw && typeof raw === "object" ? raw : null;
};