Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2521,6 +2521,19 @@ let BENCHMARKS = [
worstCaseCount: 2,
tags: ["Default", "Wasm", "dotnet"],
}),
// J2CL
new AsyncBenchmark({
name: "j2cl-box2d-wasm",
files: [
"./wasm/j2cl-box2d/benchmark.js",
"./wasm/j2cl-box2d/build/Box2dBenchmark_j2wasm_entry.js",
],
preload: {
wasmBinary: "./wasm/j2cl-box2d/build/Box2dBenchmark_j2wasm_binary.wasm",
},
iterations: 40,
tags: ["Default", "Wasm"],
}),
];


Expand Down
1 change: 1 addition & 0 deletions wasm/j2cl-box2d/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/j2cl/
77 changes: 77 additions & 0 deletions wasm/j2cl-box2d/add-fixed-run-count-api.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
diff --git a/benchmarking/java/com/google/j2cl/benchmarking/benchmarks.bzl b/benchmarking/java/com/google/j2cl/benchmarking/benchmarks.bzl
index 04c4c72007..601cafdcb5 100644
--- a/benchmarking/java/com/google/j2cl/benchmarking/benchmarks.bzl
+++ b/benchmarking/java/com/google/j2cl/benchmarking/benchmarks.bzl
@@ -95,6 +95,7 @@ def benchmark(name, deps = [], data = [], jvm_only = False, perfgate_test_tags =
"%s.%sLauncher#execute" % (benchmark_java_package, name),
"%s.%sLauncher#prepareForRunOnce" % (benchmark_java_package, name),
"%s.%sLauncher#runOnce" % (benchmark_java_package, name),
+ "%s.%sLauncher#runFixedCount" % (benchmark_java_package, name),
],
)

diff --git a/benchmarking/java/com/google/j2cl/benchmarking/templates.bzl b/benchmarking/java/com/google/j2cl/benchmarking/templates.bzl
index b75b8567dd..8e083f9aa2 100644
--- a/benchmarking/java/com/google/j2cl/benchmarking/templates.bzl
+++ b/benchmarking/java/com/google/j2cl/benchmarking/templates.bzl
@@ -34,6 +34,17 @@ public class #benchmarkName#Launcher {
benchmark.run();
benchmark = null; // Make sure it is only executed once.
}
+
+ public static void runFixedCount(int count) {
+ AbstractBenchmark bench = new #benchmarkName#();
+ bench.setupOneTime();
+ for (int i = 0; i < count; i++) {
+ bench.setup();
+ bench.run();
+ bench.tearDown();
+ }
+ bench.tearDownOneTime();
+ }
}
"""

@@ -54,7 +65,12 @@ goog.module('#benchmarkName#_launcher')

const j2wasm = goog.require('#wasm_module_name#');

-if (typeof read == 'undefined') {
+if (typeof isJetStreamDriver !== 'undefined') {
+ // Running as a JetStream benchmark; expose "instantiateAsync" to JetStream driver.
+ goog.global['instantiateAsync'] = async function(buffer) {
+ return j2wasm.instantiate(await j2wasm.compile(buffer));
+ }
+} else if (typeof read == 'undefined') {
// Running on browser, fetch the file from server.
j2wasm.instantiateStreaming("#wasm_url#")
.then((instance) => Object.assign(goog.global, instance.exports));
diff --git a/build_defs/internal_do_not_use/j2wasm_application.bzl b/build_defs/internal_do_not_use/j2wasm_application.bzl
index 36d3abaacd..211319deb9 100644
--- a/build_defs/internal_do_not_use/j2wasm_application.bzl
+++ b/build_defs/internal_do_not_use/j2wasm_application.bzl
@@ -50,6 +50,15 @@ async function compileStreaming(urlOrResponse) {
return WebAssembly.compileStreaming(response, options);
}

+/**
+ * @param {!BufferSource} moduleBuffer
+ * @return {!Promise<!WebAssembly.Module>}
+ * @suppress {checkTypes} Externs are missing options parameter (phase 2)
+ */
+async function compile(moduleBuffer) {
+ return WebAssembly.compile(moduleBuffer, options);
+}
+
/**
* @param {!WebAssembly.Module} module
* @return {!Promise<!WebAssembly.Instance>}
@@ -91,7 +100,7 @@ function prepareImports(module) {
return imports;
}

-exports = {compileStreaming, instantiate, instantiateStreaming, instantiateBlocking};
+exports = {compile, compileStreaming, instantiate, instantiateStreaming, instantiateBlocking};
"""

def _impl_j2wasm_application(ctx):
39 changes: 39 additions & 0 deletions wasm/j2cl-box2d/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2025 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Hook into the J2Cl application runner, enables explicit instantiation via `instantiateAsync` below.
const isJetStreamDriver = true;

// Polyfills for shells. See j2cl/bazel-j2cl/benchmarking/java/com/google/j2cl/benchmarking/templates.bzl
class TextDecoder {
decode(buffer) {
return String.fromCharCode.apply(null, new Uint8Array(buffer));
}
}
// The following polyfills are just required for imports but not actually used.
function unused_import() {
throw new Error('not supported, should be an unused import');
}
var atob = unused_import;
var btoa = unused_import;
var gc = unused_import;

class Benchmark {
wasmBinary;
wasmInstanceExports;

async init() {
this.wasmBinary = await JetStream.getBinary(JetStream.preload.wasmBinary);
}

async runIteration() {
// Compile once in the first iteration.`
if (!this.wasmInstanceExports) {
this.wasmInstanceExports = (await instantiateAsync(this.wasmBinary)).exports;
}

const internalIterations = 5;
this.wasmInstanceExports.runFixedCount(internalIterations);
}
}
5 changes: 5 additions & 0 deletions wasm/j2cl-box2d/build.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Built on 2025-08-20 17:36:29+02:00
Cloning into 'j2cl'...
fbbe1e6db2 [J2KT] Remove dangling readable files which were added by accident.
Copying generated files into build/
Build success
32 changes: 32 additions & 0 deletions wasm/j2cl-box2d/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -eo pipefail

# Cleanup old files.
rm -rf build/
rm -rf j2cl/

BUILD_LOG="$(realpath build.log)"
echo -e "Built on $(date --rfc-3339=seconds)" | tee "$BUILD_LOG"

# Build the benchmark from source.
git clone git@github.com:google/j2cl.git |& tee -a "$BUILD_LOG"
pushd j2cl/
git log -1 --oneline | tee -a "$BUILD_LOG"
git apply ../add-fixed-run-count-api.patch | tee -a "$BUILD_LOG"
BUILD_SRC_DIR="benchmarking/java/com/google/j2cl/benchmarks/octane/"
pushd "$BUILD_SRC_DIR"
bazel build //benchmarking/java/com/google/j2cl/benchmarks/octane:Box2dBenchmark_local-j2wasm-v8
popd
popd

echo "Copying generated files into build/" | tee -a "$BUILD_LOG"
mkdir -p build/ | tee -a "$BUILD_LOG"
BUILD_OUT_DIR="j2cl/bazel-bin/$BUILD_SRC_DIR"
cp $BUILD_OUT_DIR/Box2dBenchmark_j2wasm_entry.js build/ | tee -a "$BUILD_LOG"
# FIXME: Remove this workaround, once Safari/JSC implements JS-string builtins.
# Since these imports/builtins are never called in the workload, they should not have any effect on runtime.
sed -i 's/imports:/"wasm:js-string":{fromCharCodeArray:unused_import,concat:unused_import,equals:unused_import,compare:unused_import,length:unused_import,charCodeAt:unused_import,substring:unused_import},imports:/g' build/Box2dBenchmark_j2wasm_entry.js
cp $BUILD_OUT_DIR/Box2dBenchmark_j2wasm_binary.wasm build/ | tee -a "$BUILD_LOG"
cp $BUILD_OUT_DIR/Box2dBenchmark_j2wasm_binary.binaryen.symbolmap build/ | tee -a "$BUILD_LOG"
echo "Build success" | tee -a "$BUILD_LOG"
Loading
Loading