Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Big perf improvements: resolve variables at parse time
This necessitated a significant refactor in the exported API and no longer exposes the Interp struct (but that's probably better anyway). It also removes ParseExpr and Eval as parsing a stand-alone expression was problematic. For now, function names and array parameters to functions are still resolved by name at runtime. I intend to work on that later, but this gets the low-hanging fruit. This gives a significant performance improvement for many benchmarks (see below), because we're doing variable lookups by integer index instead of name, and reducing the number of allocations in many cases. benchmark old ns/op new ns/op delta BenchmarkFuncCall-8 13710 5313 -61.25% BenchmarkRecursiveFunc-8 60507 30719 -49.23% BenchmarkForInLoop-8 4092 2467 -39.71% BenchmarkLocalVars-8 2959 1827 -38.26% BenchmarkForLoop-8 15706 10349 -34.11% BenchmarkIncrDecr-8 2441 1647 -32.53% BenchmarkGlobalVars-8 2628 1812 -31.05% BenchmarkCondExpr-8 867 604 -30.33% BenchmarkIfStatement-8 1194 885 -25.88% BenchmarkComparisons-8 739 606 -18.00% BenchmarkRegexMatch-8 2224 1828 -17.81% BenchmarkConcatSmall-8 1120 946 -15.54% BenchmarkBuiltinIndex-8 4659 4221 -9.40% BenchmarkBinaryOperators-8 993 905 -8.86% BenchmarkBuiltinLength-8 3040 2775 -8.72% BenchmarkBuiltinSubstr-8 4651 4303 -7.48% BenchmarkBuiltinMatch-8 4964 4640 -6.53% BenchmarkConcatLarge-8 7203914 6767577 -6.06% BenchmarkBuiltinSplitSpace-8 119347 114082 -4.41% BenchmarkSetField-8 1599 1536 -3.94% BenchmarkBuiltinGsub-8 18242 17691 -3.02% BenchmarkSimplePattern-8 248 241 -2.82% BenchmarkBuiltinSubAmpersand-8 15731 15311 -2.67% BenchmarkArrayOperations-8 2350 2410 +2.55% BenchmarkBuiltinGsubAmpersand-8 19415 18994 -2.17% BenchmarkGetField-8 585 573 -2.05% BenchmarkBuiltinSplitRegex-8 152834 149869 -1.94% BenchmarkBuiltinSub-8 15305 15092 -1.39% BenchmarkSimpleBuiltins-8 6828 6746 -1.20% BenchmarkBuiltinSprintf-8 15972 15927 -0.28%
- Loading branch information