Commit a4adba8b authored by Daniel Martí's avatar Daniel Martí

preallocate 1KiB on the stack for marshals

	name         old time/op    new time/op    delta
	Roundtrip-8    4.35µs ± 1%    4.27µs ± 0%  -1.92%  (p=0.004 n=6+5)

	name         old alloc/op   new alloc/op   delta
	Roundtrip-8    6.86kB ± 0%    6.86kB ± 0%  +0.01%  (p=0.004 n=5+6)

	name         old allocs/op  new allocs/op  delta
	Roundtrip-8       112 ± 0%       106 ± 0%  -5.36%  (p=0.002 n=6+6)
parent fd4638f3
......@@ -36,7 +36,11 @@ func Marshal(inNode ipld.Node, out io.Writer) error {
if err != nil {
return err
}
var enc []byte
// 1KiB can be allocated on the stack, and covers most small nodes
// without having to grow the buffer and cause allocations.
enc := make([]byte, 0, 1024)
if links.Length() > 0 {
// collect links into a slice so we can properly sort for encoding
pbLinks := make([]pbLink, links.Length())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment