'beforeCommit-slow' ​Contract 2.0.0 · package sha256
a857eca95b35921109faf997094bb4192f12527d9d0fcd4be7e97f06425bad6e· generated fromconfigurator-runtime.d.ts,tables/problems.jsonandservices/onsite-scripter/scripts/contract-docs-what-to-do.jsonbyservices/onsite-scripter/scripts/build-contract-docs.mjs; edit the source, not this file.
A member of ProblemCode · stable · since 2.0.0
A beforeCommit function averaged over about 5 ms across its last 10 commits; recorded at most once per function per 10 s, with the count and the mean in message.
Keep each session.beforeCommit function under 5 ms (the mean over its last 10 commits; message has it): do only the layout arithmetic and the commit.tx writes inside it, read sizes you measured once per asset outside it (cache what labs.geometry.read returns), and never load assets in it. The hook is labs: register it through has(session, 'beforeCommit') (has from the package root) with an on('committed') fallback, as below.
const widths = new Map<string, number>(); // measured once per asset, outside the hook
const row = async (writer: Writer): Promise<void> => {
let x = 0;
for (const n of writer.getSceneModel()?.root ?? []) {
await writer.node(n.nodeId).set({ pose: { position: { x, y: 0, z: 0 } } });
x += widths.get(n.nodeId) ?? 0;
}
};
has(session, 'beforeCommit') // either branch unregisters when `signal` aborts
? session.beforeCommit('row', (commit) => row(commit.tx), { signal })
// keep this branch: a runtime without the labs hook gets the same writes, one frame later
: session.on('committed', ({ recorded }) => { if (recorded) void row(session); }, { signal });
Session.beforeCommit: Keep it under 5 ms ('beforeCommit-slow'); never load assets (engine queries such as labs.geometry.read are allowed, so it may be async; cache their results); mint ids from state, never at random.The set is open: handle a code you don't know ('other').
hold/rules/rule-5 (tables/hold.json)