Skip to content

Commit 6ecda6e

Browse files
cfallinJakeChampionJake Champion
authored
feat: Add option to enable PBL. (#628)
The Portable Baseline Interpreter (PBL, pronounced "pebble") is a new execution tier developed for the SpiderMonkey JS engine. PBL fits into the tier hierarchy just above the generic interpreter ("C++ interpreter") and below the "baseline interpreter". Unlike the true "baseline interpreter", PBL does not require code generation (JIT'ing): it consists of an interpreter loop for JS opcodes in pure C++, but maintains data structures (strict JIT stack frame layout, use of IC data) as the other baseline tiers do. Crucially, PBL also allows use of ICs (inline caches) by including a generic CacheIR interpreter that can execute the dynamically-generated "IC stubs" with fastpathed behavior as it is discovered. PBL thus leverages existing engine functionality (JIT frame management, CacheIR) and applies it to a new use-case (no JIT). PBL itself was merged into our fork of SpiderMonkey in bytecodealliance/gecko-dev#9, and I have sent a detailed design document and a link to the patch-set upstream to see about merging this into SpiderMonkey proper. The design doc will be opened up soon as well. PBL has been found to improve performance over the generic C++ interpreter, the only other tier available without codegen: by 1.6x in the best cases, and a geomean on Octane of +16% (with more opportunity as followup work is done), on Octane-like workloads. It passes all jit-tests and Web Platform Tests. These performance results are on Wasmtime (or Viceroy) on x86-64; on aarch64 (including e.g. Apple Silicon) the performance of Wasm br_table (switch) instructions is not as good, so interpreters are slower generally, and PBL may not show as significant speedups as on x86-64 hosts. We're working on this issue as well. This PR consists of changes from Jake Champion [email protected] to add a --enable-pbl option to the SDK's CLI (from draft PR #619) and then a version-bump of the SpiderMonkey submodule to one that includes my PBL patches. PBL is off by default (until further testing establishes its stability and benefits) and should not affect builds that do not explicitly include the above flag. Co-authored-by: Jake Champion <[email protected]> Co-authored-by: Jake Champion <[email protected]>
1 parent f4a649a commit 6ecda6e

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

js-compute-runtime-cli.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { printHelp } from "./src/printHelp.js";
66
import { addSdkMetadataField } from "./src/addSdkMetadataField.js";
77

88
const {
9+
enablePBL,
910
enableExperimentalHighResolutionTimeMethods,
1011
wasmEngine,
1112
input,
@@ -28,7 +29,7 @@ if (version) {
2829
// it could be that the user is using an older version of js-compute-runtime
2930
// and a newer version does not support the platform they are using.
3031
const {compileApplicationToWasm} = await import('./src/compileApplicationToWasm.js')
31-
await compileApplicationToWasm(input, output, wasmEngine, enableExperimentalHighResolutionTimeMethods);
32+
await compileApplicationToWasm(input, output, wasmEngine, enableExperimentalHighResolutionTimeMethods, enablePBL);
3233
if (component) {
3334
const {compileComponent} = await import('./src/component.js');
3435
await compileComponent(output, adapter);

runtime/js-compute-runtime/js-compute-runtime.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "js/ContextOptions.h"
1717
#include "js/Initialization.h"
1818
#include "js/SourceText.h"
19+
#include "jsapi.h"
1920

2021
#pragma clang diagnostic pop
2122

@@ -122,6 +123,14 @@ bool init_js() {
122123
return false;
123124
}
124125

126+
bool ENABLE_PBL = std::string(std::getenv("ENABLE_PBL")) == "1";
127+
if (ENABLE_PBL) {
128+
JS_SetGlobalJitCompilerOption(cx, JSJitCompilerOption::JSJITCOMPILER_PORTABLE_BASELINE_ENABLE,
129+
1);
130+
JS_SetGlobalJitCompilerOption(
131+
cx, JSJitCompilerOption::JSJITCOMPILER_PORTABLE_BASELINE_WARMUP_THRESHOLD, 0);
132+
}
133+
125134
// TODO: check if we should set a different creation zone.
126135
JS::RealmOptions options;
127136
options.creationOptions().setStreamsEnabled(true).setWeakRefsEnabled(

src/compileApplicationToWasm.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { precompile } from "./precompile.js";
88
import { bundle } from "./bundle.js";
99
import { containsSyntaxErrors } from "./containsSyntaxErrors.js";
1010

11-
export async function compileApplicationToWasm(input, output, wasmEngine, enableExperimentalHighResolutionTimeMethods = false) {
11+
export async function compileApplicationToWasm(input, output, wasmEngine, enableExperimentalHighResolutionTimeMethods = false, enablePBL = false) {
1212
try {
1313
if (!(await isFile(input))) {
1414
console.error(
@@ -99,7 +99,8 @@ export async function compileApplicationToWasm(input, output, wasmEngine, enable
9999
shell: true,
100100
encoding: "utf-8",
101101
env: {
102-
ENABLE_EXPERIMENTAL_HIGH_RESOLUTION_TIME_METHODS: enableExperimentalHighResolutionTimeMethods ? '1' : '0'
102+
ENABLE_EXPERIMENTAL_HIGH_RESOLUTION_TIME_METHODS: enableExperimentalHighResolutionTimeMethods ? '1' : '0',
103+
ENABLE_PBL: enablePBL ? '1' : '0',
103104
}
104105
}
105106
);

src/parseInputs.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export async function parseInputs(cliInputs) {
99
let component = false;
1010
let adapter;
1111
let enableExperimentalHighResolutionTimeMethods = false;
12+
let enablePBL = false;
1213
let customEngineSet = false;
1314
let wasmEngine = join(__dirname, "../js-compute-runtime.wasm");
1415
let customInputSet = false;
@@ -32,6 +33,10 @@ export async function parseInputs(cliInputs) {
3233
enableExperimentalHighResolutionTimeMethods = true;
3334
break;
3435
}
36+
case "--enable-pbl": {
37+
enablePBL = true;
38+
break;
39+
}
3540
case "-V":
3641
case "--version": {
3742
return { version: true };
@@ -104,5 +109,5 @@ export async function parseInputs(cliInputs) {
104109
}
105110
}
106111
}
107-
return { wasmEngine, component, adapter, input, output, enableExperimentalHighResolutionTimeMethods };
112+
return { wasmEngine, component, adapter, input, output, enableExperimentalHighResolutionTimeMethods, enablePBL };
108113
}

0 commit comments

Comments
 (0)