Cache approved dynamic descriptors per operation

This commit is contained in:
2026-10-25 22:07:37 +00:00
parent 12d350a292
commit 08f2a8f3e9
3 changed files with 88 additions and 8 deletions

View File

@@ -24,21 +24,25 @@ type valueVisit struct {
length int
}
// valueOperation owns one traversal's cycle and budget state and reuses the
// current load's descriptor cache for dynamic values.
// valueOperation owns one traversal's cycle and budget state, and caches
// dynamic descriptors approved for that traversal.
type valueOperation struct {
cloneMode secretCloneMode
schema *schemaDescriptor
limits projectionLimits
active map[valueVisit]bool
nodes int
nodeCredits int
cloneMode secretCloneMode
schema *schemaDescriptor
limits projectionLimits
active map[valueVisit]bool
approvedDynamic map[reflect.Type]*typeDescriptor
nodes int
nodeCredits int
}
func (o *valueOperation) dynamicDescriptor(current reflect.Type, path Path) (*typeDescriptor, *projectionIssue) {
if o.schema.secrets.Type != nil && current == o.schema.secrets.Type {
return nil, &projectionIssue{code: CodeSchemaDynamicType, path: path.clone(), message: "dynamic configuration values cannot establish secret-reference semantics"}
}
if descriptor, approved := o.approvedDynamic[current]; approved {
return descriptor, nil
}
builder := schemaBuilder{cache: o.schema.types, building: make(map[reflect.Type]bool), secrets: o.schema.secrets}
descriptor, issue := builder.describe(current, path)
if issue != nil {
@@ -49,6 +53,10 @@ func (o *valueOperation) dynamicDescriptor(current reflect.Type, path Path) (*ty
builder.rollback()
return nil, &projectionIssue{code: CodeSchemaDynamicType, path: path.clone(), message: "dynamic configuration values cannot establish secret-reference semantics"}
}
if o.approvedDynamic == nil {
o.approvedDynamic = make(map[reflect.Type]*typeDescriptor)
}
o.approvedDynamic[current] = descriptor
return descriptor, nil
}