Reuse owned assembly across configuration layers
This commit is contained in:
@@ -42,6 +42,68 @@ func BenchmarkOverlayRecursiveMappings(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkOverlayManyApplications(b *testing.B) {
|
||||
for _, count := range []int{32, 64, 128} {
|
||||
inputs := make([]*document.Node, count)
|
||||
for index := range inputs {
|
||||
inputs[index] = benchmarkCatalog("source-2", index, 1)
|
||||
}
|
||||
benchmarkOverlayApplications(b, count, inputs)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkOverlayRepeatedReplacement(b *testing.B) {
|
||||
for _, count := range []int{32, 64, 128} {
|
||||
inputs := make([]*document.Node, count)
|
||||
for index := range inputs {
|
||||
location := document.Location{SourceID: "source-2"}
|
||||
value := &document.Node{Kind: document.String, Text: "replacement", Location: location}
|
||||
if index%2 == 0 {
|
||||
value = &document.Node{Kind: document.Mapping, Location: location, Mapping: []document.Entry{{
|
||||
Key: "enabled", Value: &document.Node{Kind: document.Boolean, Text: "false", Location: location},
|
||||
}}}
|
||||
}
|
||||
inputs[index] = &document.Node{Kind: document.Mapping, Location: location, Mapping: []document.Entry{{
|
||||
Key: "catalog", Value: &document.Node{Kind: document.Mapping, Location: location, Mapping: []document.Entry{{
|
||||
Key: "item-0", Value: value,
|
||||
}}},
|
||||
}}}
|
||||
}
|
||||
benchmarkOverlayApplications(b, count, inputs)
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkOverlayApplications(b *testing.B, count int, inputs []*document.Node) {
|
||||
base, diagnostics := composeDocuments(benchmarkCatalog("source-1", 0, 1))
|
||||
if len(diagnostics) != 0 {
|
||||
b.Fatal(diagnostics)
|
||||
}
|
||||
for _, mode := range []string{"owned", "copy-preserving"} {
|
||||
b.Run(mode+"/"+strconv.Itoa(count), func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for range b.N {
|
||||
if mode == "owned" {
|
||||
assembly := newAssemblyAccumulator(cloneComposedDocument(base))
|
||||
for _, input := range inputs {
|
||||
if diagnostics := assembly.applyOverlay(input, nil, nil, LayerOverlay); len(diagnostics) != 0 {
|
||||
b.Fatal(diagnostics)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
current := base
|
||||
for _, input := range inputs {
|
||||
current, diagnostics = overlayDocuments(current, input)
|
||||
if len(diagnostics) != 0 {
|
||||
b.Fatal(diagnostics)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkCatalog(source string, first, width int) *document.Node {
|
||||
location := document.Location{SourceID: source}
|
||||
entries := make([]document.Entry, width)
|
||||
|
||||
Reference in New Issue
Block a user