Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0c21849
Compile a cppia script's local functions under the JIT
dimensionscape Nov 27, 2026
faf90bd
Call script closures from cppia scripts without boxing
dimensionscape Nov 27, 2026
da09051
Read object array elements in place under the cppia JIT
dimensionscape Nov 27, 2026
f635250
Add a cppia workload shaped like BunnyMark's update loop
dimensionscape Nov 27, 2026
78ce891
Compare the cppia workloads with HashLink in the bench
dimensionscape Nov 28, 2026
8da1825
Add a cppia workload shaped like an OpenFL application's frame
dimensionscape Nov 28, 2026
81bfce1
Call compiled script closures directly from jitted cppia code
dimensionscape Nov 28, 2026
d88c533
Merge main into feature/cppia-perf-b621b5
dimensionscape Nov 28, 2026
83aaedf
Merge main into feature/cppia-perf-b621b5
dimensionscape Nov 28, 2026
fdd330c
Call unoverridden host methods directly from jitted cppia code
dimensionscape Nov 28, 2026
12e3bb9
Give a scriptable host's static functions typed entries for scripts
dimensionscape Nov 28, 2026
915255b
Merge main into feature/cppia-perf-b621b5
dimensionscape Nov 28, 2026
d74ecf2
Check unused cppia casts to classes and interfaces under the JIT
dimensionscape Nov 28, 2026
152b1bd
Call script closures from host code without boxing their arguments
dimensionscape Nov 28, 2026
2b76f39
Add a cppia workload that sorts a script's Ints with its comparator
dimensionscape Nov 28, 2026
818b6e9
Sort with a script comparator without boxing the values
dimensionscape Nov 28, 2026
7f2efdd
Copy a cppia closure's captures from a list its function keeps
dimensionscape Nov 28, 2026
b7e7e20
Keep the host's typed call into a compiled cppia closure in line
dimensionscape Nov 29, 2026
6862d3e
Merge main into feature/cppia-perf-b621b5
dimensionscape Nov 29, 2026
695a02d
Call host instance methods from jitted cppia code through typed entries
dimensionscape Nov 29, 2026
20dc636
Call host static functions from jitted cppia code through typed entries
dimensionscape Nov 29, 2026
f417921
Keep a typed host call's object and result in registers
dimensionscape Nov 29, 2026
12ed1b3
Box Ints and Floats with the allocator's fast path in line
dimensionscape Nov 29, 2026
ce4bc1a
Check and enter a cppia closure in line from jitted code
dimensionscape Nov 29, 2026
373a966
Add a cppia workload whose closure result is an operator's operand
dimensionscape Nov 29, 2026
142b4d3
Add a cppia workload of a script's map and filter
dimensionscape Nov 29, 2026
5fa2bef
Sort with a script comparator as a run of typed calls
dimensionscape Nov 29, 2026
f9f36f2
Read Int and Float boxes in line for jitted Dynamic operators
dimensionscape Nov 29, 2026
8578bda
Call a cppia closure directly when its result is wanted as a Dynamic
dimensionscape Nov 29, 2026
369f97c
Keep a jitted cppia function's Int and Float locals in saved registers
dimensionscape Nov 29, 2026
4912e65
Read a jitted cppia operator's operands where they are
dimensionscape Nov 29, 2026
c3d45af
Declare only the scratch registers jitted cppia code uses
dimensionscape Nov 29, 2026
832d0ce
Call a jitted cppia closure from host code through a compiled entry
dimensionscape Dec 3, 2026
50496e7
Merge main into feature/cppia-perf-b621b5
dimensionscape Dec 3, 2026
78fa893
Make the new cppia JIT tests print the same on every platform
dimensionscape Dec 3, 2026
c65f8be
Leave Float conversions past an Int out of CppiaJitDynamicNumbers
dimensionscape Dec 3, 2026
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
20 changes: 20 additions & 0 deletions BENCHMARKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ driver also checks that the interpreter and JIT return the same checksum.
| `closure_call` | Script calls to a closure that updates a captured variable |
| `native_call` | Script-to-native calls with an Int argument and result |
| `native_callback` | A native loop calling a script closure that updates a captured variable |
| `bunny_update` | The update loop of OpenFL's BunnyMark over 2,000 script objects that extend a host class, moved through its Float properties, in a listener the host calls once a frame |
| `openfl_frame` | An OpenFL application's frame: 1,000 script objects extending a host display object, moved by an ENTER_FRAME listener the host calls, one in ten with a closure listener of its own, a small object made each update, dead ones replaced, and a host render reading every transform |
| `call_by_name` | Script calls of an abstract's methods over a host type, which the host gives no binding for, as openfl.Vector's are: length, element reads and writes |
| `host_sort` | `Array.sort`, which is host code, sorting a copy of 1,000 script Ints with a comparator the script gives it, ten times a run |
| `host_statics` | Script reads and writes of a host class's static object fields |
| `closure_expr` | Script calls to a closure whose result is an operand of an operator, which takes it as a Dynamic |
| `script_map` | `Array.map` and `filter` on 1,000 Ints, ten times a run, which Haxe inlines into the script as loops calling the closures |

The native timing harness loads one script module per process. Loading, linking,
booting and JIT compilation happen in `setup()`, outside the timed samples.
Expand All @@ -151,6 +158,18 @@ so those flags do not change the native benchmarks. Peak memory for these cases
includes the host, loaded module and any JIT code. The `noop` startup row still
measures the native executable.

### HashLink as a reference

`--hl <path to hl>` also runs the CPPIA workloads on HashLink's JIT. `bench/hl`
builds `Script.hx` and `bench/cppia/shared` straight to HashLink with the same
harness, workload table and timing, so there the host's side of each workload
is HashLink JIT code too, where under cppia it is native C++. Its processes take
turns with the others on the `cppia_jit_` benchmarks and must give the same
checksums, and the CPPIA table gains an HL/JIT column and the JIT's ratio to it.
A host with its framework compiled in should not run a script slower than
HashLink runs the whole application, so a ratio below 1 there is a target.


## Running it yourself

You need Haxe 4.3, the C++ compiler hxcpp uses on your platform, and curl.
Expand All @@ -160,6 +179,7 @@ cd bench
haxe --run Run # every benchmark, both runtimes
haxe --run Run --only map_int,sort_int
haxe --run Run --only cppia_interp_native_call,cppia_jit_native_call
haxe --run Run --only cppia_jit_closure_call --hl path/to/hl # with HashLink beside it
haxe --run Run --no-build # reuse the last builds
haxe --run Run --only gc_object_ids --define HXCPP_GC_GENERATIONAL
haxe --run Run --readme # publish: this page and the README summary
Expand Down
22 changes: 22 additions & 0 deletions Changes.md

Large diffs are not rendered by default.

63 changes: 60 additions & 3 deletions bench/Run.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ using StringTools;
--warmup <n> untimed samples per process (default 2)
--no-build reuse the existing builds
--out <file> results JSON (default .work/results.json)
--hl <hl executable> also run the CPPIA workloads on HashLink's JIT, as a
reference for the cppia JIT: bench/hl builds them,
with the bridge in bench/cppia/shared, straight to
HashLink, so the host's side runs as HashLink JIT
code. Its processes take turns with the others on
the cppia_jit_ benchmarks and must give the same
checksums, and the CPPIA table gains an HL column
--readme publish the results: the full tables go into
BENCHMARKS.md and a summary of the key measures into
README.md. Needs every benchmark, both runtimes and a
Expand Down Expand Up @@ -98,6 +105,8 @@ class Run {
static var build = true;
static var outFile:Null<String> = null;
static var writeReadme = false;
static var hlExe:Null<String> = null;
static var hl:Null<Runtime> = null;

static function main() {
benchDir = FileSystem.absolutePath(".");
Expand Down Expand Up @@ -148,6 +157,14 @@ class Run {
Sys.println('${rt.label}: ${rt.env.compiler}, ${rt.env.pointerBits}-bit, API level ${rt.env.apiLevel}');
}
checkComparable(runtimes);
if (hlExe != null && needsCppia()) {
hl = new Runtime("hl", hlLabel(), workDir + "/hl");
if (build)
buildHl();
if (!FileSystem.exists(hl.dir + "/bench.hl"))
fail('${hl.label}: ${hl.dir}/bench.hl is missing; run without --no-build');
Sys.println('${hl.label}: ${hlExe}');
}

var names = listBenchmarks(runtimes[0]);
if (needsCppia())
Expand Down Expand Up @@ -178,7 +195,7 @@ class Run {
failures++;
Sys.println('FAILED: ${r.error}');
} else
Sys.println([for (rt in runtimes) '${rt.label} ${formatRate(r.byRuntime.get(rt.name).rate, r.unit)}'].join(", "));
Sys.println([for (rt in (hl != null && r.byRuntime.exists(hl.name) ? runtimes.concat([hl]) : runtimes)) '${rt.label} ${formatRate(r.byRuntime.get(rt.name).rate, r.unit)}'].join(", "));
results.push(r);
}

Expand All @@ -188,6 +205,7 @@ class Run {
haxe: commandOutput("haxe", ["-version"]),
libhxcpp: gitDescribe(),
runtimes: [for (rt in runtimes) {name: rt.name, label: rt.label, commit: rt.commit, env: rt.env, cppiaEnv: rt.cppiaEnv}],
hashlink: hl == null ? null : {name: hl.name, label: hl.label, exe: hlExe},
skipped: skipped,
settings: {runs: runs, samples: samples, warmup: warmup},
startup: [for (rt in runtimes) {name: rt.name, seconds: startup[rt.name]}],
Expand Down Expand Up @@ -261,6 +279,10 @@ class Run {
build = false;
case "--out":
outFile = FileSystem.absolutePath(value());
case "--hl":
hlExe = FileSystem.absolutePath(value());
if (!FileSystem.exists(hlExe))
fail('--hl: $hlExe does not exist');
case "--readme":
writeReadme = true;
default:
Expand Down Expand Up @@ -374,6 +396,24 @@ class Run {
return true;
}

/** Builds the CPPIA workloads for HashLink with bench/hl's harness. **/
static function buildHl() {
FileSystem.createDirectory(hl.dir);
Sys.println('Building ${hl.label} (log: ${hl.dir}/build.log)');
var command = 'haxe -cp "${benchDir}/hl" -cp "${benchDir}/cppia" -cp "${benchDir}/cppia/shared" -main HlMain -hl bench.hl';
if (inDir(hl.dir, () -> Sys.command('$command > build.log 2>&1')) != 0) {
var log = File.getContent(hl.dir + "/build.log").split("\n");
Sys.println(log.slice(log.length > 40 ? log.length - 40 : 0).join("\n"));
fail('${hl.label}: build failed');
}
}

/** "HashLink 1.16.0", from the executable's own --version. **/
static function hlLabel():String {
var version = commandOutput(hlExe, ["--version"]);
return version == "" ? "HashLink" : 'HashLink $version';
}

static function needsCppia():Bool {
if (!cppia)
return false;
Expand Down Expand Up @@ -428,6 +468,8 @@ class Run {
}

static function runBenchmark(name:String, runtimes:Array<Runtime>):BenchResult {
if (hl != null && name.startsWith("cppia_jit_"))
runtimes = runtimes.concat([hl]);
var result = new BenchResult(name);
var raw = [for (rt in runtimes) rt.name => new Array<Dynamic>()];
var checksum:Null<Int> = null;
Expand Down Expand Up @@ -543,6 +585,10 @@ class Run {
if (compare)
all.push('${modes[mode]} vs stock');
}
if (hl != null && lib != null) {
all.push('HL/JIT, ${hl.label}');
all.push('JIT vs HL');
}
b.add("| " + all.join(" | ") + " |\n");
b.add("|" + [for (i in 0...all.length) i < first.length ? " --- " : " ---: "].join("|") + "|\n");
for (workload in cppia) {
Expand All @@ -559,6 +605,15 @@ class Run {
row += " | " + ratio(r.byRuntime.get(lib.name).rate, r.byRuntime.get(stock.name).rate,
Math.max(r.byRuntime.get(lib.name).spread, r.byRuntime.get(stock.name).spread), LAYOUT_BAND);
}
if (hl != null && lib != null) {
var r = byName['cppia_jit_$workload'];
var h = r == null ? null : r.byRuntime.get(hl.name);
if (h == null || r.error != null)
row += " | failed | ";
else
row += " | " + formatRate(h.rate, null) + " ±" + percent(h.spread) + " | "
+ ratio(r.byRuntime.get(lib.name).rate, h.rate, Math.max(r.byRuntime.get(lib.name).spread, h.spread), LAYOUT_BAND);
}
b.add(row + " |\n");
}
}
Expand Down Expand Up @@ -736,8 +791,10 @@ class Run {

/** Runs the benchmark executable and returns its stdout; throws if it fails. **/
static function benchProcess(rt:Runtime, args:Array<String>, cppia = false):String {
var exe = cppia || args[0].startsWith("cppia_") ? rt.cppiaExe : rt.exe;
var p = new Process(exe, args);
var p = if (rt.name == "hl")
new Process(hlExe, [rt.dir + "/bench.hl"].concat(args));
else
new Process(cppia || args[0].startsWith("cppia_") ? rt.cppiaExe : rt.exe, args);
var out = p.stdout.readAll().toString();
var err = p.stderr.readAll().toString();
var code = p.exitCode();
Expand Down
Loading
Loading