google / go-jsonnet

Apache License 2.0
1.61k stars 231 forks source link

feat: Go implementation for manifestYamlDoc and escapeStringJson #742

Closed jgraeger closed 3 months ago

jgraeger commented 8 months ago

This PR introduces native Go implementations for two standard library functions in Jsonnet: manifestYamlDoc and escapeStringJson. These enhancements are a response to performance challenges, especially noticeable in cases where quote_keys=false is set. This issue is documented in google/jsonnet#1019 and also holds for the Go implementation.

Benchmarks

Running Before Test... (10s)
Running After Test... (10s)
benchmark                                old ns/op     new ns/op     delta
Benchmark_Builtin_escapeStringJson-8     9061562       3082901       -65.98%
Benchmark_Builtin_manifestYamlDoc-8      12660395      3559494       -71.88%

On a large, non-public codebase generating megabytes of yaml from jsonnet, the runtime decreased from over 10 minutes to 8 seconds.