Skip to content

Commit ceacba1

Browse files
authored
Benchmark fixes and improvements (#10870)
We had an annoying little bug where we set CFLAGS so that feature flags work, but some build systems don't append that - they just replace all their defaults with it. As a result, on the zlib test we were measuring unoptimized code (lol) which was over 30% larger and almost half the speed it should be... Add an LTO mode for emscripten. LTO sometimes helps by a small amount, but it's mixed, and can also hurt by a little bit too on code size, due to much more inlining. But in some cases it helps a lot, like 25% smaller code in fasta, 8% smaller in coremark, and a 25% speedup on skinning. Run v8 without liftoff. The baseline compiler can add a lot of noise since how much time we spend there ends up mattering a lot (the wasm runs at half speed until the full compiler is done, and that's noisy). Also add nicer code for error handling in the zlib benchmark.
1 parent d6aced8 commit ceacba1

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

tests/benchmark/test_zlib_benchmark.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ void __attribute__ ((noinline)) doit(unsigned char *buffer, int size, int i) {
2929
unsigned long decompressedSize = size;
3030
uncompress(buffer3, &decompressedSize, buffer2, (int)compressedSize);
3131
assert(decompressedSize == size);
32-
if (i == 0) assert(strcmp((char*)buffer, (char*)buffer3) == 0);
32+
if (i == 0) {
33+
if (strcmp((char*)buffer, (char*)buffer3) != 0) {
34+
puts("incorrect output!");
35+
abort();
36+
}
37+
puts("output looks good");
38+
}
3339
}
3440

3541
int main(int argc, char **argv) {

tests/test_benchmark.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ def build(self, parent, filename, args, shared_args, emcc_args, native_args, nat
191191
llvm_root = self.env.get('LLVM') or LLVM_ROOT
192192
if lib_builder:
193193
env_init = self.env.copy()
194-
env_init['CFLAGS'] = ' '.join(LLVM_FEATURE_FLAGS)
194+
# Note that we need to pass in all the flags here because some build
195+
# systems (like zlib) if they see a CFLAGS it will override all their
196+
# default flags, including optimizations.
197+
env_init['CFLAGS'] = ' '.join(LLVM_FEATURE_FLAGS + [OPTIMIZATIONS] + self.extra_args)
195198
emcc_args = emcc_args + lib_builder('js_' + llvm_root, native=False, env_init=env_init)
196199
final = os.path.dirname(filename) + os.path.sep + self.name + ('_' if self.name else '') + os.path.basename(filename) + '.js'
197200
final = final.replace('.cpp', '')
@@ -313,22 +316,35 @@ def cleanup(self):
313316
# NativeBenchmarker('clang', CLANG_CC, CLANG),
314317
# NativeBenchmarker('gcc', 'gcc', 'g++')
315318
]
316-
if SPIDERMONKEY_ENGINE and SPIDERMONKEY_ENGINE in shared.JS_ENGINES:
317-
benchmarkers += [
318-
# EmscriptenBenchmarker('sm', SPIDERMONKEY_ENGINE),
319-
]
319+
320320
if V8_ENGINE and V8_ENGINE in shared.JS_ENGINES:
321+
# avoid the baseline compiler running, because it adds a lot of noise
322+
# (the nondeterministic time it takes to get to the full compiler ends up
323+
# mattering as much as the actual benchmark)
324+
aot_v8 = V8_ENGINE + ['--no-liftoff']
325+
default_v8_name = os.environ.get('EMBENCH_NAME') or 'v8'
321326
benchmarkers += [
322-
EmscriptenBenchmarker(os.environ.get('EMBENCH_NAME') or 'v8', V8_ENGINE),
327+
EmscriptenBenchmarker(default_v8_name, aot_v8),
328+
EmscriptenBenchmarker(default_v8_name + '-lto', aot_v8, ['-flto']),
323329
]
324-
if shared.NODE_JS and shared.NODE_JS in shared.JS_ENGINES:
330+
if os.path.exists(CHEERP_BIN):
331+
benchmarkers += [
332+
# CheerpBenchmarker('cheerp-v8-wasm', aot_v8),
333+
]
334+
335+
if SPIDERMONKEY_ENGINE and SPIDERMONKEY_ENGINE in shared.JS_ENGINES:
336+
# TODO: ensure no baseline compiler is used, see v8
325337
benchmarkers += [
326-
EmscriptenBenchmarker('Node.js', shared.NODE_JS),
338+
# EmscriptenBenchmarker('sm', SPIDERMONKEY_ENGINE),
327339
]
328-
if os.path.exists(CHEERP_BIN):
340+
if os.path.exists(CHEERP_BIN):
341+
benchmarkers += [
342+
# CheerpBenchmarker('cheerp-sm-wasm', SPIDERMONKEY_ENGINE),
343+
]
344+
345+
if shared.NODE_JS and shared.NODE_JS in shared.JS_ENGINES:
329346
benchmarkers += [
330-
# CheerpBenchmarker('cheerp-sm-wasm', SPIDERMONKEY_ENGINE),
331-
# CheerpBenchmarker('cheerp-v8-wasm', V8_ENGINE),
347+
# EmscriptenBenchmarker('Node.js', shared.NODE_JS),
332348
]
333349

334350

0 commit comments

Comments
 (0)