Skip to content

c++ impl 100x+ slower than golang impl #826

Open
@githubaccount888

Description

@githubaccount888

The C++ jsonnet implementation is orders of magnitude slower than the golang implementation. I hit the issue using std.sort() but the issue may very well be broader than that. Both were run with v0.16.0. The attached example uses a 10000 element list but the issue is still obvious down with lengths around ~1000. Based on my testing it appears the C++ version also scales worse than golang as the problem size increases.

test.txt

C++

$ time $(./jsonnet test.txt &> /dev/null)
real	0m18.887s
user	0m18.800s
sys	0m0.085s

golang

$ time $(~/.go/bin/jsonnet test.txt &> /dev/null)
real	0m0.079s
user	0m0.095s
sys	0m0.017s

As far as I can tell C++ is still the recommended "reference" implementation, so it's quite surprising to see it perform so poorly. I originally hit the problem evaluating jsonnet through Python bindings ("jsonnet" module) -- there is an analogous gojsonnet module but that requires installing the entire golang toolchain, which is an absurdly heavy dependency just for evaluating jsonnet.

I know nothing about the jsonnet codebase, but just poking around for 5 seconds it appears they supposedly share the same std library implementation (which is written in jsonnet), so at first glance this behavior was even more surprising. Digging slightly deeper, however, it looks like the golang implementation ends up overriding certain functions in builtins.go (presumably to fix performance issues). If that's true, it seems like the same steps should have also been taken in the true "recommended" C++ implementation (or better yet just fix in the std library itself and remove the implementation-specific behavior).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions