This way, calls to Unmarshal or Decoder.Decode allocate once
at the start rather than twice.
│ old │ new │
│ allocs/op │ allocs/op vs base │
Unmarshal/HugoFrontMatter-8 141.0 ± 0% 140.0 ± 0% -0.71% (p=0.002 n=6)
* go.mod: bump minimum and language to 1.21
CI only tests Go 1.21 and 1.22, and older versions of Go are no longer
getting any bug or security fixes, so advertise that we only support
Go 1.21 or later via go.mod.
While here, ensure the module is tidy and resolve deprecation warnings,
and remove now-unnecessary Go version build tags.
* replace sort.Slice with slices.SortFunc
The latter is more efficient, and allocates less, since sort.Slice
needs to go through sort.Interface which causes allocations.
goos: linux
goarch: amd64
pkg: github.com/pelletier/go-toml/v2/benchmark
cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics
│ old │ new │
│ sec/op │ sec/op vs base │
Marshal/HugoFrontMatter-8 7.612µ ± 1% 6.730µ ± 1% -11.59% (p=0.002 n=6)
│ old │ new │
│ B/s │ B/s vs base │
Marshal/HugoFrontMatter-8 65.52Mi ± 1% 74.11Mi ± 1% +13.11% (p=0.002 n=6)
│ old │ new │
│ B/op │ B/op vs base │
Marshal/HugoFrontMatter-8 5.672Ki ± 0% 5.266Ki ± 0% -7.16% (p=0.002 n=6)
│ old │ new │
│ allocs/op │ allocs/op vs base │
Marshal/HugoFrontMatter-8 85.00 ± 0% 73.00 ± 0% -14.12% (p=0.002 n=6)
When decoding into a non-empty slice, it needs to be emptied so that only the
tables contained in the document are present in the resulting value.
Arrays are not impacted because their unmarshal offset is tracked separately.
Fixes#931
Parser did not track the location of the faulty inline table in the
document, and unmarshaler tried to the use the non-raw data field of the
AST node, both resulting into a panic when generating the parser error.
Fixes#850
Uses the existing method to DRY up the error message generation, and decorates
with position index where needed. No behaviour is changed, but it allows for
further changes to make error messaging more specific.
Related to: pelletier/go-toml#806
As discussed[1], this change allows times to provide precision beyond the
nanosecond (nine digits fractional part). Extra precision is truncated according
to the TOML specificiation.
[1]: https://github.com/pelletier/go-toml/discussions/707
The goal is to provide some context as to why the type were mismatched. This
change only works for that case, on structs. This is the same a encoding/json. A
more general solution would be great, but this would require a broader change in
the decoder, which I don't think is necessary at the moment.
Fixes#628
The TOML spec is being clarified to say that dotted keys "define" their
intermediate tables. Therefore the seen tracker needs to verify that none of
them reference an explicit table.
Also added a missing seen expression check for key-values parsed as part of a
table section.
See https://github.com/toml-lang/toml/issues/846
* Use pointers instead of copying around ast.Node
Node is a 56B struct that is constantly in the hot path. Passing nodes
around by copy had a cost that started to add up. This change replaces
them by pointers. Using unsafe pointer arithmetic and converting
sibling/child indexes to relative offsets, it removes the need to carry
around a pointer to the root of the tree. This saves 8B per Node. This
space will be used to store an extra []byte slice to provide contextual
error handling on all nodes, including the ones whose data is different
than the raw input (for example: strings with escaped characters), while
staying under the size of a cache line.
* Remove conditional
* Add Raw to track range in data for parsed values
* Simplify reference tracking
* Benchmark script
* Rewrite unmarshaler using the stack
Instead of tracking the build chain using `target`s, use the stack
instead.
Working and most benchmarks look good, but regression on structs unmarshalling.
~60% slower on ReferenceFile/struct.
* Shortcut to check if last node of iterator
* Remove unecessary pointer allocation
* Skip over unused keys without marking them as seen
* Add some tests
* Fix mktemp on macos