hexops / valast

Convert Go values to their AST
Other
308 stars 16 forks source link

Add type expression cache (66% performance improvement) #10

Closed slimsag closed 3 years ago

slimsag commented 3 years ago

With complex data types, this can provide a 66% performance improvement.

Before:

$ go test -bench=.
goos: darwin
goarch: amd64
pkg: github.com/hexops/valast
BenchmarkComplexType-16            2     564812395 ns/op
PASS
ok      github.com/hexops/valast    9.372s

After:

$ go test -bench=.
goos: darwin
goarch: amd64
pkg: github.com/hexops/valast
BenchmarkComplexType-16            6     189646854 ns/op
PASS
ok      github.com/hexops/valast    6.379s

In practice this can result in tests running much faster, before:

--- PASS: TestUnionMerge (6.38s)
    --- PASS: TestUnionMerge/#00 (1.42s)
    --- PASS: TestUnionMerge/#01 (1.17s)
    --- PASS: TestUnionMerge/#02 (2.32s)
    --- PASS: TestUnionMerge/#03 (0.00s)
    --- PASS: TestUnionMerge/#04 (0.00s)
    --- PASS: TestUnionMerge/#05 (1.46s)

After:

--- PASS: TestUnionMerge (2.96s)
    --- PASS: TestUnionMerge/#00 (1.05s)
    --- PASS: TestUnionMerge/#01 (0.77s)
    --- PASS: TestUnionMerge/#02 (0.77s)
    --- PASS: TestUnionMerge/#03 (0.00s)
    --- PASS: TestUnionMerge/#04 (0.00s)
    --- PASS: TestUnionMerge/#05 (0.37s)

Also appears to fix https://github.com/hexops/autogold/issues/16

Signed-off-by: Stephen Gutekanst stephen@hexops.com