parser: Improve TOML frontmatter parser performance
authorAlbert Nigmatzianov <albertnigma@gmail.com>
Mon, 20 Mar 2017 05:47:46 +0000 (10:47 +0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 20 Mar 2017 08:02:35 +0000 (09:02 +0100)
Difference between toml.Load(string(datum)) and
toml.LoadReader(bytes.NewReader(datum)):
benchmark           old ns/op     new ns/op     delta
BenchmarkLoad-4     82068         78489         -4.36%

benchmark           old allocs     new allocs     delta
BenchmarkLoad-4     494            493            -0.20%

benchmark           old bytes     new bytes     delta
BenchmarkLoad-4     17009         16913         -0.56%

parser/frontmatter.go

index d97bc4c4d5cc0c34b678ec579b0c48c449a3cc3a..b773fe5ce751d3e7de5ff181761593ceaf195133 100644 (file)
@@ -176,8 +176,7 @@ func HandleTOMLMetaData(datum []byte) (interface{}, error) {
        m := map[string]interface{}{}
        datum = removeTOMLIdentifier(datum)
 
-       tree, err := toml.Load(string(datum))
-
+       tree, err := toml.LoadReader(bytes.NewReader(datum))
        if err != nil {
                return m, err
        }