Skip to content

Instantly share code, notes, and snippets.

@malkia
Created June 24, 2018 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malkia/975e1620799d63d52f283110271592dc to your computer and use it in GitHub Desktop.
Save malkia/975e1620799d63d52f283110271592dc to your computer and use it in GitHub Desktop.
jsonnet - no dynamic casts when gc's heap
../jsonnet-perf-tests.sh 2>&1 | tee ../results.txt
set -xe
for i in master less_dynamic_casts
do
git checkout $i
git rev-parse HEAD
bazel build --compilation_mode=opt //cmd:jsonnet
for j in perf_tests/*.jsonnet
do
time -p bazel-bin/cmd/jsonnet $j -o /dev/null
done
done
It was discovered that dynamic_cast can be prohibitely expensive, especially if it's call more than one time per operation.
Instead the type can be directly stored as enum.
Previously some removal of dynamic_cast was done in here: https://github.com/google/jsonnet/commit/97a24f7026e95d2dde1894ab86f96373047a21f7 with one spcific benchmark showing 200% faster
Some more dynamic_casts<> were found, and the first one is the Heap gc code: https://github.com/malkia/jsonnet/commit/d6c64fe1daa13a5f32fa019b5a0300b08a2447e6
Initial results are showing 10-20% speed increase using the 4 perf_tests (../results.txt)
Two shell scripts were provided for testing (they need to be placed in the parent of the git folder).
+++ for i in master less_dynamic_casts
+++ git checkout master
Already on 'master'
Your branch is up to date with 'origin/master'.
+++ git rev-parse HEAD
237fa08c183cd332d9d399ddc45d6a8acccd87e2
+++ bazel build --compilation_mode=opt //cmd:jsonnet
Loading:
Loading: 0 packages loaded
INFO: Analysed target //cmd:jsonnet (0 packages loaded).
INFO: Found 1 target...
[0 / 1] [-----] BazelWorkspaceStatusAction stable-status.txt
Target //cmd:jsonnet up-to-date:
bazel-bin/cmd/jsonnet
INFO: Elapsed time: 0.306s, Critical Path: 0.01s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
+++ for j in perf_tests/*.jsonnet
+++ bazel-bin/cmd/jsonnet perf_tests/large_string_join.jsonnet -o /dev/null
real 92.25
user 77.80
sys 12.43
+++ for j in perf_tests/*.jsonnet
+++ bazel-bin/cmd/jsonnet perf_tests/large_string_template.jsonnet -o /dev/null
real 107.64
user 106.89
sys 0.25
+++ for j in perf_tests/*.jsonnet
+++ bazel-bin/cmd/jsonnet perf_tests/realistic1.jsonnet -o /dev/null
real 160.64
user 160.12
sys 0.06
+++ for j in perf_tests/*.jsonnet
+++ bazel-bin/cmd/jsonnet perf_tests/realistic2.jsonnet -o /dev/null
real 192.25
user 191.24
sys 0.75
+++ for i in master less_dynamic_casts
+++ git checkout less_dynamic_casts
Switched to branch 'less_dynamic_casts'
Your branch is ahead of 'origin/less_dynamic_casts' by 1 commit.
(use "git push" to publish your local commits)
+++ git rev-parse HEAD
d6c64fe1daa13a5f32fa019b5a0300b08a2447e6
+++ bazel build --compilation_mode=opt //cmd:jsonnet
Loading:
Loading: 0 packages loaded
INFO: Analysed target //cmd:jsonnet (0 packages loaded).
INFO: Found 1 target...
[0 / 5] [-----] BazelWorkspaceStatusAction stable-status.txt
[11 / 14] Compiling core/vm.cpp; 1s processwrapper-sandbox
[11 / 14] Compiling core/vm.cpp; 10s processwrapper-sandbox
[12 / 14] [-----] Linking cmd/jsonnet
Target //cmd:jsonnet up-to-date:
bazel-bin/cmd/jsonnet
INFO: Elapsed time: 22.576s, Critical Path: 21.99s
INFO: 2 processes: 2 processwrapper-sandbox.
INFO: Build completed successfully, 3 total actions
INFO: Build completed successfully, 3 total actions
+++ for j in perf_tests/*.jsonnet
+++ bazel-bin/cmd/jsonnet perf_tests/large_string_join.jsonnet -o /dev/null
real 85.36
user 75.07
sys 9.86
+++ for j in perf_tests/*.jsonnet
+++ bazel-bin/cmd/jsonnet perf_tests/large_string_template.jsonnet -o /dev/null
real 95.48
user 95.16
sys 0.22
+++ for j in perf_tests/*.jsonnet
+++ bazel-bin/cmd/jsonnet perf_tests/realistic1.jsonnet -o /dev/null
real 129.98
user 129.87
sys 0.03
+++ for j in perf_tests/*.jsonnet
+++ bazel-bin/cmd/jsonnet perf_tests/realistic2.jsonnet -o /dev/null
real 171.84
user 171.02
sys 0.74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment