git.delta.rocks / jrsonnet / refs/commits / 587f5b8c40c1

difftreelog

ci add benchmarks against other implementations

Yaroslav Bolyukin2022-11-20parent: #f16d3b8.patch.diff
in: master

5 files changed

addednix/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
modifiednix/benchmarks.nixdiffbeforeafterboth
1{ stdenv, jrsonnet, go-jsonnet, sjsonnet, jsonnet, hyperfine }:1{ lib
22, runCommand
3, jsonnet-bundler
4, cacert
5, stdenv
6, fetchFromGitHub
7, jrsonnet
8, go-jsonnet
9, sjsonnet
10, jsonnet
11, hyperfine
12, quick ? false
13}:
14let
15 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 let
35 src = fetchFromGitHub {
36 owner = "prometheus-operator";
37 repo = "kube-prometheus";
38 rev = "6a570e3154eac26e32da61d784fbe626da4804df";
39 hash = "sha256-s6BK8KQiSjql2w6R+8m5pvPPAcKW+SKjQwqxZHjimFw=";
40 };
41 in
42 runCommand "kube-prometheus-vendor"
43 {
44 outputHash = "sha256-R60RI/7FQPOHisnzANb34m9WPj5D9FeMVoGOjB19zl8=";
45 outputHashMode = "recursive";
46 buildInputs = [ cacert ];
47 }
48 ''
49 mkdir -p $out
50 cp -r ${src}/* $out/
51 cd $out
52 mkdir vendor
53 ${jsonnet-bundler}/bin/jb install
54 '';
55
56 skipSlow = if quick then "slow benchmark" else "";
57in
3stdenv.mkDerivation {58stdenv.mkDerivation {
4 name = "benchmarks";59 name = "benchmarks";
5 __impure = true;60 __impure = true;
6 unpackPhase = "true";61 unpackPhase = "true";
62
63 buildInputs = [
64 jrsonnet
65 go-jsonnet
66 sjsonnet
67 jsonnet
68
69 hyperfine
70 ];
771
8 installPhase = "touch $out";72 installPhase =
73 let
74 mkBench = { name, path, omitSource ? false, pathIsGenerator ? false, skipScala ? "", skipCpp ? "", skipGo ? "", vendor ? "" }: ''
75 set -oux
76
77 echo >> $out
78 echo "### ${name}" >> $out
79 echo >> $out
80 ${if skipGo != "" then ''
81 echo "> Note: No results for Go, ${skipGo}" >> $out
82 echo >> $out
83 '' else ""}
84 ${if skipScala != "" then ''
85 echo "> Note: No results for Scala, ${skipScala}" >> $out
86 echo >> $out
87 '' else ""}
88 ${if skipCpp != "" then ''
89 echo "> Note: No results for C++, ${skipCpp}" >> $out
90 echo >> $out
91 '' else ""}
92 echo "<details>" >> $out
93 echo "<summary>Source</summary>" >> $out
94 echo >> $out
95 echo "\`\`\`jsonnet" >> $out
96 ${if pathIsGenerator then "echo \"// Generator source\" >> $out" else ""}
97 cat ${if omitSource then "// Omitted: too large" else path} >> $out
98 echo >> $out
99 echo "\`\`\`" >> $out
100 echo "</details>" >> $out
101 echo >> $out
102 path=${path}
103 ${if pathIsGenerator then ''
104 jrsonnet $path > generated.jsonnet
105 path=generated.jsonnet
106 '' else ""}
107 hyperfine -N ${if quick then "-r1" else ""} --output=pipe --style=basic --export-markdown result.md \
108 "jrsonnet $path ${if vendor != "" then "-J${vendor}" else ""}" -n "Rust" \
109 ${if skipGo == "" then "\"go-jsonnet $path ${if vendor != "" then "-J ${vendor}" else ""}\" -n \"Go\"" else "" } \
110 ${if skipScala == "" then "\"sjsonnet $path ${if vendor != "" then "-J ${vendor}" else ""}\" -n \"Scala\"" else "" } \
111 ${if skipCpp == "" then "\"jsonnet $path ${if vendor != "" then "-J ${vendor}" else ""}\" -n \"C++\"" else "" }
112 cat result.md >> $out
113 '';
114 in
115 ''
116 touch $out
117 cat ${./benchmarks.md} >> $out
118 echo >> $out
119
120 echo "<details>" >> $out
121 echo "<summary>Tested versions</summary>" >> $out
122 echo >> $out
123 echo Rust: git as $(date +'%d.%m.%Y' -u) >> $out
124 echo >> $out
125 echo "\`\`\`" >> $out
126 jrsonnet --help >> $out
127 echo "\`\`\`" >> $out
128 echo >> $out
129 echo Go: $(go-jsonnet --version) >> $out
130 echo >> $out
131 echo "\`\`\`" >> $out
132 go-jsonnet --help >> $out
133 echo "\`\`\`" >> $out
134 echo >> $out
135 echo C++: $(jsonnet --version) >> $out
136 echo >> $out
137 echo "\`\`\`" >> $out
138 jsonnet --help >> $out
139 echo "\`\`\`" >> $out
140 echo >> $out
141 echo Scala: >> $out
142 echo >> $out
143 echo "\`\`\`" >> $out
144 sjsonnet 2>> $out || true
145 echo "\`\`\`" >> $out
146 echo >> $out
147 echo "</details>" >> $out
148 echo >> $out
149
150 echo >> $out
151 echo "## Real world" >> $out
152 ${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;}}
154
155 echo >> $out
156 echo "## Benchmarks from C++ jsonnet (/perf_tests)" >> $out
157 ${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;}}
161
162 echo >> $out
163 echo "## Benchmarks from C++ jsonnet (/benchmarks)" >> $out
164 ${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;}}
173
174 echo >> $out
175 echo "## Benchmarks from Go jsonnet (builtins)" >> $out
176 ${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 '';
9}189}
10190
modifiednix/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;
modifiednix/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;
modifiednix/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"
   '';
 }