Compiling a schema with deeply nested, multiply-referenced model groups was exponential: groupReferenceParticle inlined each <xs:group ref> into the Particle content model, so g0=(g1,g1), g1=(g2,g2), ... built 2^K particles (depth 14 = 0.21s, depth 20 ~13-18s). The expansion is now memoized per (group definition, cycle-visiting set) in a per-compile GroupParticleMemo shared across the value copies XSDContext.scoped/visiting make, so sibling references share it and the build drops to O(groups) (depth 40 now ~0.016s; previously infeasible). The shared content term is reused by value (copy-on-write), so the compiled model is identical and validation is unchanged: the XSTS gate holds (invalid-schemas- accepted 15, valid-schemas-rejected 0, instance buckets unchanged) and the streaming-vs-tree fuzz differential still passes. This closes the schema-compile half of the interactive-safety group blowup (companion to the positionCap determinism fix); a depth-40 compile test guards against regression. Full suite, style, namespacing, and WASM all pass.
23 lines
1.2 KiB
Swift
23 lines
1.2 KiB
Swift
extension PureXML.Schema {
|
|
/// The key under which an `<xs:group>` reference's expansion is memoized: the
|
|
/// group DEFINITION node and the cycle-visiting set at the reference site. The
|
|
/// expansion is determined by these (the namespace scope is fixed per
|
|
/// definition), so two references that share them share the result.
|
|
struct GroupParticleMemoKey: Hashable {
|
|
let definition: ObjectIdentifier
|
|
let visiting: Set<String>
|
|
}
|
|
|
|
/// Memoizes group-reference expansion during one schema compile. A
|
|
/// multiply-referenced nested group (`g0=(g1,g1), g1=(g2,g2), …`) otherwise
|
|
/// rebuilds each subtree per reference, an exponential `2^K` compile; sharing the
|
|
/// expansion across sibling references drops the build to `O(groups)`. The
|
|
/// resulting `Particle` is semantically identical (a value type, so the shared
|
|
/// content term is copy-on-write), only built once. A reference type so it is
|
|
/// shared across the value copies `XSDContext.scoped`/`visiting` make; one
|
|
/// instance per compile.
|
|
final class GroupParticleMemo {
|
|
var store: [GroupParticleMemoKey: PureXML.Schema.Particle] = [:]
|
|
}
|
|
}
|