Merge pull request #22236 from g4lb/perf/tree-node-marshal

data: call Node.MarshalJSON directly when building a tree
This commit is contained in:
Michael Eischer authored and GitHub committed 2026-12-02 22:28:21 +01:00
commit b21617d3dc
2 files changed
+4 -2

No files matched your search

+3 -1
View File
@@ -302,7 +302,9 @@ func (builder *TreeJSONBuilder) AddNode(node *Node) error {
}
builder.lastName = node.Name
val, err := json.Marshal(node)
// Call MarshalJSON directly: json.Marshal would only validate and copy its
// output, which is already compact.
val, err := node.MarshalJSON()
if err != nil {
return err
}
+1 -1
View File
@@ -245,7 +245,7 @@ func BenchmarkBuildTree(b *testing.B) {
nodes := make([]data.Node, size)
for i := range nodes {
// Archiver.SaveTree inputs in sorted order, so do that here too.
nodes[i].Name = strconv.Itoa(i)
nodes[i].Name = fmt.Sprintf("%03d", i)
}
b.ResetTimer()