Every schema compilation in actor generate-schema-types performs two full deep clones:
clearAllRequired(schema) / makePropertiesRequired(schema) — each does structuredClone internally
stripTitles(schemaToCompile) — does another structuredClone at the top of the function
All three functions guarantee immutability (tested), so the second clone in stripTitles is redundant when the caller already holds a disposable copy from step 1.
For the current schemas this has zero practical impact, but it is wasteful and worth cleaning up.
Options
Plan A — { mutate: true } flag on stripTitles
Minimal API change. When the caller already has a disposable clone, it opts out of the internal clone:
export function stripTitles(schema, { mutate = false } = {}) {
const result = mutate ? schema : structuredClone(schema);
// all internal recursive calls pass { mutate: true }
...
}
// call site — schemaToCompile is already a clone, skip second structuredClone
stripTitles(schemaToCompile, { mutate: true })
Plan B — combined prepareForCompilation(schema, allOptional) helper
Single clone, applies both the required-field transformation and title-stripping in one pass. Requires extracting private mutating helpers for each transform. Call sites become a single function call but the internal refactor is larger.
Reference
Introduced in #1000.
Every schema compilation in
actor generate-schema-typesperforms two full deep clones:clearAllRequired(schema)/makePropertiesRequired(schema)— each doesstructuredCloneinternallystripTitles(schemaToCompile)— does anotherstructuredCloneat the top of the functionAll three functions guarantee immutability (tested), so the second clone in
stripTitlesis redundant when the caller already holds a disposable copy from step 1.For the current schemas this has zero practical impact, but it is wasteful and worth cleaning up.
Options
Plan A —
{ mutate: true }flag onstripTitlesMinimal API change. When the caller already has a disposable clone, it opts out of the internal clone:
Plan B — combined
prepareForCompilation(schema, allOptional)helperSingle clone, applies both the required-field transformation and title-stripping in one pass. Requires extracting private mutating helpers for each transform. Call sites become a single function call but the internal refactor is larger.
Reference
Introduced in #1000.