geofffranks / spruce

A BOSH template merge tool
MIT License
433 stars 78 forks source link

Implement some best practices, fix error in static_ips test & avoid excessive regex calls when line is not spruce line #382

Open adberger opened 1 month ago

adberger commented 1 month ago

Hi there

I've made a few changes, the biggest one being the matchPattern function which should make spruce much faster especially when rendering larges files.

If you are open to a review (& possible merge), I ask you to do it thoroughly as I don't have much experience with Go.

Here is a benchmark comparsion from our tool, which uses spruce under the hood:

Before:

BenchmarkExecute-12            1        8906495459 ns/op        65408706864 B/op        679075642 allocs/op
PASS
ok      github.com/bedag/subst/subst/cmd        9.524s

After:

BenchmarkExecute-12            1        1447321000 ns/op        1864258368 B/op 20667868 allocs/op
PASS
ok      github.com/bedag/subst/subst/cmd        2.065s

Memory consumption went down from ~60GB to ~1GB, so much less garbage collection.

adberger commented 3 weeks ago

@geofffranks Do you consider reviewing & merging this? :)