difftreelog
ci add benchmarks against other implementations
in: master
5 files changed
nix/benchmarks.mddiffbeforeafterboth--- /dev/null
+++ b/nix/benchmarks.md
@@ -0,0 +1,7 @@
+# Benchmarks
+
+There are multiple implementations of jsonnet implemented in different languages: Rust (this repo), [Go](https://github.com/google/go-jsonnet/), [Scala](https://github.com/databricks/sjsonnet), [C++](https://github.com/google/jsonnet), [Haskell](https://github.com/moleike/haskell-jsonnet).
+
+For simplicity, I will call these implementations by the language of their implementation.
+
+Unfortunately, I haven't managed to measure performance of Haskell implementation, because I wasn't able to build it, and there is no binaries published anywhere, so this implementation is omitted from the following benchmarks
nix/benchmarks.nixdiffbeforeafterboth1{ stdenv, jrsonnet, go-jsonnet, sjsonnet, jsonnet, hyperfine }:23stdenv.mkDerivation {4 name = "benchmarks";5 __impure = true;6 unpackPhase = "true";78 installPhase = "touch $out";9}1{ lib2, runCommand3, jsonnet-bundler4, cacert5, stdenv6, fetchFromGitHub7, jrsonnet8, go-jsonnet9, sjsonnet10, jsonnet11, hyperfine12, quick ? false13}:14let15 jsonnetBench = fetchFromGitHub {16 rev = "v0.19.1";17 owner = "google";18 repo = "jsonnet";19 hash = "sha256-q1MNdbyrx4vvN5woe0o90pPqaNtsZjI5RQ7KJt7rOpU=";20 };21 goJsonnetBench = (fetchFromGitHub {22 owner = "google";23 repo = "go-jsonnet";24 rev = "v0.19.1";25 hash = "sha256-FgQYnas0qkIedRAA8ApZXLzEylg6PS6+8zzl7j+yOeI=";26 }) + "/builtin-benchmarks";27 graalvmBench = fetchFromGitHub {28 owner = "oracle";29 repo = "graal";30 rev = "bc305df3fe587960f7635f0185571500e5988475";31 hash = "sha256-4EKB1b2o4/qtYQ+nqbbs621OJrtjApsAWEBcw5EjrYc=";32 };33 kubePrometheusBench =34 let35 src = fetchFromGitHub {36 owner = "prometheus-operator";37 repo = "kube-prometheus";38 rev = "6a570e3154eac26e32da61d784fbe626da4804df";39 hash = "sha256-s6BK8KQiSjql2w6R+8m5pvPPAcKW+SKjQwqxZHjimFw=";40 };41 in42 runCommand "kube-prometheus-vendor"43 {44 outputHash = "sha256-R60RI/7FQPOHisnzANb34m9WPj5D9FeMVoGOjB19zl8=";45 outputHashMode = "recursive";46 buildInputs = [ cacert ];47 }48 ''49 mkdir -p $out50 cp -r ${src}/* $out/51 cd $out52 mkdir vendor53 ${jsonnet-bundler}/bin/jb install54 '';5556 skipSlow = if quick then "slow benchmark" else "";57in58stdenv.mkDerivation {59 name = "benchmarks";60 __impure = true;61 unpackPhase = "true";6263 buildInputs = [64 jrsonnet65 go-jsonnet66 sjsonnet67 jsonnet6869 hyperfine70 ];7172 installPhase =73 let74 mkBench = { name, path, omitSource ? false, pathIsGenerator ? false, skipScala ? "", skipCpp ? "", skipGo ? "", vendor ? "" }: ''75 set -oux7677 echo >> $out78 echo "### ${name}" >> $out79 echo >> $out80 ${ifskipGo!=""then''81 echo "> Note: No results for Go, ${skipGo}" >> $out82 echo >> $out83 ''else""}84 ${ifskipScala!=""then''85 echo "> Note: No results for Scala, ${skipScala}" >> $out86 echo >> $out87 ''else""}88 ${ifskipCpp!=""then''89 echo "> Note: No results for C++, ${skipCpp}" >> $out90 echo >> $out91 ''else""}92 echo "<details>" >> $out93 echo "<summary>Source</summary>" >> $out94 echo >> $out95 echo "\`\`\`jsonnet" >> $out96 ${ifpathIsGeneratorthen"echo \"// Generator source\" >> $out"else""}97 cat ${ifomitSourcethen"// Omitted: too large"elsepath} >> $out98 echo >> $out99 echo "\`\`\`" >> $out100 echo "</details>" >> $out101 echo >> $out102 path=${path}103 ${ifpathIsGeneratorthen''104 jrsonnet $path > generated.jsonnet105 path=generated.jsonnet106 ''else""}107 hyperfine -N ${ifquickthen"-r1"else""} --output=pipe --style=basic --export-markdown result.md \108 "jrsonnet $path ${ifvendor!=""then"-J${vendor}"else""}" -n "Rust" \109 ${ifskipGo==""then"\"go-jsonnet $path ${ifvendor!=""then"-J ${vendor}"else""}\" -n \"Go\""else"" } \110 ${ifskipScala==""then"\"sjsonnet $path ${ifvendor!=""then"-J ${vendor}"else""}\" -n \"Scala\""else"" } \111 ${ifskipCpp==""then"\"jsonnet $path ${ifvendor!=""then"-J ${vendor}"else""}\" -n \"C++\""else"" }112 cat result.md >> $out113 '';114 in115 ''116 touch $out117 cat ${} >> $out118 echo >> $out119120 echo "<details>" >> $out121 echo "<summary>Tested versions</summary>" >> $out122 echo >> $out123 echo Rust: git as $(date +'%d.%m.%Y' -u) >> $out124 echo >> $out125 echo "\`\`\`" >> $out126 jrsonnet --help >> $out127 echo "\`\`\`" >> $out128 echo >> $out129 echo Go: $(go-jsonnet --version) >> $out130 echo >> $out131 echo "\`\`\`" >> $out132 go-jsonnet --help >> $out133 echo "\`\`\`" >> $out134 echo >> $out135 echo C++: $(jsonnet --version) >> $out136 echo >> $out137 echo "\`\`\`" >> $out138 jsonnet --help >> $out139 echo "\`\`\`" >> $out140 echo >> $out141 echo Scala: >> $out142 echo >> $out143 echo "\`\`\`" >> $out144 sjsonnet 2>> $out || true145 echo "\`\`\`" >> $out146 echo >> $out147 echo "</details>" >> $out148 echo >> $out149150 echo >> $out151 echo "## Real world" >> $out152 ${mkBench{name="Graalvm CI";path="${graalvmBench}/ci.jsonnet";skipCpp=skipSlow;}}153 ${mkBench{name="Kube-prometheus manifests";vendor="${kubePrometheusBench}/vendor";path="${kubePrometheusBench}/example.jsonnet";skipCpp=skipSlow;}}154155 echo >> $out156 echo "## Benchmarks from C++ jsonnet (/perf_tests)" >> $out157 ${mkBench{name="Large string join";path="${jsonnetBench}/perf_tests/large_string_join.jsonnet";}}158 ${mkBench{name="Large string template";omitSource=true;path="${jsonnetBench}/perf_tests/large_string_template.jsonnet";skipGo="fails with os stack size exhausion";skipCpp=skipSlow;}}159 ${mkBench{name="Realistic 1";path="${jsonnetBench}/perf_tests/realistic1.jsonnet";skipGo=skipSlow;skipCpp=skipSlow;}}160 ${mkBench{name="Realistic 2";path="${jsonnetBench}/perf_tests/realistic2.jsonnet";skipGo=skipSlow;skipCpp=skipSlow;}}161162 echo >> $out163 echo "## Benchmarks from C++ jsonnet (/benchmarks)" >> $out164 ${mkBench{name="Tail call";path="${jsonnetBench}/benchmarks/bench.01.jsonnet";}}165 ${mkBench{name="Inheritance recursion";path="${jsonnetBench}/benchmarks/bench.02.jsonnet";skipCpp=skipSlow;}}166 ${mkBench{name="Simple recursive call";path="${jsonnetBench}/benchmarks/bench.03.jsonnet";}}167 ${mkBench{name="Foldl string concat";path="${jsonnetBench}/benchmarks/bench.04.jsonnet";}}168 ${mkBench{name="Array sorts";path="${jsonnetBench}/benchmarks/bench.06.jsonnet";skipScala="std.reverse is not implemented";skipCpp=skipSlow;}}169 ${mkBench{name="Lazy array";path="${jsonnetBench}/benchmarks/bench.07.jsonnet";}}170 ${mkBench{name="Inheritance function recursion";path="${jsonnetBench}/benchmarks/bench.08.jsonnet";}}171 ${mkBench{name="String strips";path="${jsonnetBench}/benchmarks/bench.09.jsonnet";skipCpp=skipSlow;}}172 ${mkBench{name="Big object";path="${jsonnetBench}/benchmarks/gen_big_object.jsonnet";pathIsGenerator=true;}}173174 echo >> $out175 echo "## Benchmarks from Go jsonnet (builtins)" >> $out176 ${mkBench{name="std.base64";path="${goJsonnetBench}/base64.jsonnet";skipCpp=skipSlow;}}177 ${mkBench{name="std.base64Decode";path="${goJsonnetBench}/base64Decode.jsonnet";skipCpp=skipSlow;}}178 ${mkBench{name="std.base64DecodeBytes";path="${goJsonnetBench}/base64DecodeBytes.jsonnet";skipCpp=skipSlow;}}179 ${mkBench{name="std.base64 (byte array)";path="${goJsonnetBench}/base64_byte_array.jsonnet";skipCpp=skipSlow;}}180 ${mkBench{name="std.foldl";path="${goJsonnetBench}/foldl.jsonnet";}}181 ${mkBench{name="std.manifestJsonEx";path="${goJsonnetBench}/manifestJsonEx.jsonnet";}}182 ${mkBench{name="std.manifestTomlEx";path="${goJsonnetBench}/manifestTomlEx.jsonnet";skipScala="std.manifestTomlEx is not implemented";}}183 ${mkBench{name="std.parseInt";path="${goJsonnetBench}/parseInt.jsonnet";}}184 ${mkBench{name="std.reverse";path="${goJsonnetBench}/reverse.jsonnet";skipScala="std.reverse is not implemented";}}185 ${mkBench{name="std.substr";path="${goJsonnetBench}/substr.jsonnet";}}186 ${mkBench{name="Comparsion for array";path="${goJsonnetBench}/comparison.jsonnet";skipScala="array comparsion is not implemented";skipCpp=skipSlow;}}187 ${mkBench{name="Comparsion for primitives";path="${goJsonnetBench}/comparison2.jsonnet";skipCpp="can't run: uses up to 192GB of RAM";}}188 '';189}nix/go-jsonnet.nixdiffbeforeafterboth--- a/nix/go-jsonnet.nix
+++ b/nix/go-jsonnet.nix
@@ -1,4 +1,4 @@
-{ lib, buildGo119Module, fetchFromGitHub }:
+{ lib, buildGo119Module, fetchFromGitHub, makeWrapper }:
buildGo119Module rec {
pname = "go-jsonnet";
@@ -11,11 +11,13 @@
rev = "${version}";
hash = "sha256-J+bGdbYo2Ch3ORYD57yJA4jiPiS8IYASZ6kJHhyaqeU=";
};
+ vendorHash = "sha256-j1fTOUpLx34TgzW94A/BctLrg9XoTtb3cBizhVJoEEI=";
- vendorHash = "sha256-j1fTOUpLx34TgzW94A/BctLrg9XoTtb3cBizhVJoEEI=";
+ buildInputs = [ makeWrapper ];
postInstall = ''
mv $out/bin/jsonnet $out/bin/go-jsonnet
+ wrapProgram $out/bin/go-jsonnet --add-flags "--max-stack 200000"
'';
doCheck = false;
nix/jrsonnet.nixdiffbeforeafterboth--- a/nix/jrsonnet.nix
+++ b/nix/jrsonnet.nix
@@ -1,22 +1,33 @@
-{ lib, fetchFromGitHub, rustPlatform }:
+{ lib, fetchFromGitHub, rustPlatform, runCommand, makeWrapper }:
let
- jsonnet = fetchFromGitHub {
- rev = "v${version}";
- owner = "google";
- repo = "jsonnet";
- hash = "sha256-q1MNdbyrx4vvN5woe0o90pPqaNtsZjI5RQ7KJt7rOpU=";
+ filteredSrc = builtins.path {
+ name = "jrsonnet-src-filtered";
+ filter = path: type: !(builtins.baseNameOf path == "flake.nix" || builtins.baseNameOf path == "nix");
+ path = ../.;
};
+
+ # for some reason, filteredSrc hash still depends on nix directory contents
+ # Moving it into a CA store drops leftover references
+ src = runCommand "jrsonnet-src"
+ {
+ __contentAddressed = true;
+ } "cp -r '${filteredSrc}' $out";
in
rustPlatform.buildRustPackage rec {
+ inherit src;
pname = "jrsonnet";
version = "git";
- src = ./..;
+ cargoTestFlags = [ "--package=jrsonnet --features=mimalloc,legacy-this-file" ];
+ cargoBuildFlags = [ "--package=jrsonnet --features=mimalloc,legacy-this-file" ];
+
+ buildInputs = [ makeWrapper ];
- cargoTestFlags = [ "--package=jrsonnet" ];
- cargoBuildFlags = [ "--package=jrsonnet" ];
+ postInstall = ''
+ wrapProgram $out/bin/jrsonnet --add-flags "--max-stack=200000 --os-stack=200000"
+ '';
cargoLock = {
lockFile = ../Cargo.lock;
nix/jsonnet.nixdiffbeforeafterboth--- a/nix/jsonnet.nix
+++ b/nix/jsonnet.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, jekyll, fetchFromGitHub }:
+{ stdenv, lib, jekyll, fetchFromGitHub, makeWrapper }:
stdenv.mkDerivation rec {
pname = "jsonnet";
@@ -15,8 +15,11 @@
"jsonnet"
];
+ buildInputs = [ makeWrapper ];
+
installPhase = ''
mkdir -p $out/bin
cp jsonnet $out/bin/jsonnet
+ wrapProgram $out/bin/jsonnet --add-flags "--max-stack 200000"
'';
}