Slice pending import encoding and reuse completed immutable plans

This commit is contained in:
2026-11-11 04:29:11 +08:00
parent 210bc14074
commit 5eabca5056
5 changed files with 48 additions and 5 deletions
@@ -118,6 +118,11 @@ export async function sealRecoveryImageAsync(formatVersion:ImageVersion,rootRevi
function* encode(plan:Prepared,depth=0,key=''):Generator<Promise<void>,Encoded,void>{
if(plan===null||typeof plan!=='object')return normalize(plan,depth,key);
if('height' in plan)return plan;
// Preparation must capture every unsafe occurrence before yielding. Once an
// earlier occurrence has assembled a proven immutable source, later plans
// can reuse that fact without rebuilding the same JSON containers.
const cached=immutable.get(plan.source);
if(cached){if(depth+cached.height>64)throw fault('invalid_recovery_payload');return cached;}
let height=0,bytes=2,reusable=true,properties=0;
const array=plan.keys===undefined,result:Json[]|Record<string,Json>=array?[]:{};
for(let index=0;index<plan.children.length;index++){