Didn't know this was a thing now. That certainly helps! Also some
follow-up fixes from the previous modernize PR.
---------
Signed-off-by: Anders Eknert <anders.eknert@apple.com>
Signed-off-by: Charlie Egan <charlie_egan@apple.com>
Co-authored-by: Charlie Egan <charlie_egan@apple.com>
This wasn't really work I planned to do, and not driven by performance
requirements. Just stumbled upon the metadata parsing code and thought
it could be made better looking. And I think it is now, while also
performing a bit better. Almost all the remaining cost now is unmarshalling
YAML though, so I think this is about as good as it gets. Also added two
new benchmarks for this.
Signed-off-by: Anders Eknert <anders.eknert@apple.com>
- Bump golangci-lint -> 2.6.2
- Fix all `deprecatedComment` "notices should be in a dedicated paragraph, separated from the rest" reports
- Enable `appendCombine` and fix all "appendCombine: can combine chain of X appends into one" notices
- Enable `preferFprint` and fix the few reported issues
- Fix various issues reported only once or twice, like `zeroByteRepeat`
Signed-off-by: Anders Eknert <anders.eknert@apple.com>
While we can't use interned `Term`s in the parser (mutable), we
can use interned `Value`s (immutable) and put in those terms. Seeing
how often we would allocate a new `Value` for e.g. "input" or "data"
made me want to try interning for vars. Just like all things interning,
this is slightly experimental and clearly marked as such. Worth highlighting
here is that the majority of vars allocated in at least Regal is however
those generated in eval.go.. and their names don't lend themselves well
to interning beforehand. Perhaps we can find a way to change that later,
as those account for a million+ allocations in `regal lint bundle`. Oh well.
Also some general improvements in the parser code, reducing allocations often
simply by moving things around in order to not evaluate (potentially allocating)
code before it's needed.
Signed-off-by: Anders Eknert <anders@eknert.com>
Have done this some time in the past, but there was a few
new issues this would highlight now that we're on Go 1.24.
Mostly:
- Use `b.Loop()` in benchmarks
- Use `strings.SplitSeq` where possible
- Remove `omitempty` tag for types that can't be empty
Signed-off-by: Anders Eknert <anders@eknert.com>
Just a little something that came up when testing `json/v2`.
Not a big issue, but also makes no sense to instantiate a new
parser when it won't be needed.
**Before/after**
```
BenchmarkParseSome/parse_some-16 162577 7317 ns/op 8088 B/op 53 allocs/op
BenchmarkParseSome/parse_some-16 135363 8754 ns/op 10536 B/op 69 allocs/op
```
Signed-off-by: Anders Eknert <anders@eknert.com>
Add enter/leave helpers that bump a depth counter and fail with
ErrMaxParsingRecursionDepthExceeded once the limit (default 100k)
is reached. Every recursive parse helper now calls them.
Expose WithMaxRecursionDepth for callers that need higher limits.
If limit is set to 0 then recursion tracking is effectively disabled.
Tests utilise a much lower depth limit.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
And update code to conform to the rule.
- Replace unnecessary fmt.Sprintf with string concatenation
- Replace fmt.Sprint with more efficient strconv.Itoa
- Replace static fmt.Errorf calls with more efficient errors.New
Thanks @srenatus for pushing me down this rabbit hole!
Signed-off-by: Anders Eknert <anders@styra.com>