Hand-written Verse rewrites of Fortnite's native functions, benchmarked against the natives on three runtimes.
Each rewrite and its native are timed on three runtimes:
- New VM: Epic's new VerseVM (
VerseCmd), local; - BPVM local: the Blueprint VM backend that Fortnite runs (
VerseCLR, Shipping build), local; - BPVM UEFN: the same code on the server of a UEFN play session.
107 comparisons, every rewrite checked against its native on the same inputs. Full table with the code behind each row: results page (also in results/bench-results.html, data in results/table.json).
- Drop-in Verse rewrites of native functions in
bench/lib(FastMath,FastArray,FastSpatial,FastVerseSpatial,TupleMath,FastTranscendental,FastSort,FastEasing), same signatures and effects as the natives - A harness that checks every rewrite against its native (edge cases and random inputs) before timing it with
profileblocks - One launcher (
verse.cmd,tools/verse-run.sh) for the new VerseVM and the BPVM (Development and Shipping builds) - A UEFN device (
bench_device) and a sync script to run the same benchmarks in a UEFN session - Python tools that build the comparison table (
results/table.json) and the results page from raw profile output or the UEFN editor log - Experiments on struct construction cost and SpatialMath
- Windows with WSL (Ubuntu 24.04), for the local runtimes
- The new VerseVM and BPVM runtimes built from Unreal Engine source (needs access to Epic's GitHub), installed under
~/verse-bench/{new,bpvm,ship}in WSL - Python (
py), for the table and page tools - A UEFN project, for the UEFN run
tools/verse-run.sh looks for the runtimes in $VERSE_RUNTIMES (default ~/verse-bench).
The runtimes live in WSL (Ubuntu 24.04) under ~/verse-bench/{new,bpvm,ship}; they are built from Unreal Engine source, which needs access to Epic's GitHub. Then, from Windows:
verse.cmd --vm=all bench :: new, bpvm, ship, with a comparison table
verse.cmd --vm=new,ship experiments\struct_cost.verse--vm takes new, bpvm, ship, both (new and bpvm) or all. A folder is concatenated in the order lib, harness, cli. A full --vm=all run takes a few GB of memory: never run two at once.
To rebuild the table and the page from raw outputs:
py tools/bench-table.py results/table.json new=results/raw/new.txt ship=results/raw/ship.txt uefn=results/raw/uefn.txt
py tools/bench-page.py results/table.json bench results/bench-results.htmlbash tools/uefn-sync.sh <uefn-project-dir>copieslib,harnessanduefnintoContent/NativeBench, one folder so one module. Thelibfiles get ana_prefix: UEFN compiles a folder in name order, and a type alias (verse_vector3,vec3) cannot be used before its file.- Place
bench_devicein the level and start a session. Correctness checks are off by default (RunChecks, ~100 s). - Profile lines land in the editor log (
%LOCALAPPDATA%\UnrealEditorFortnite\Saved\Logs\UnrealEditorFortnite.log) asLogVerse: VerseProfile: <tag> <ms> ms;bench-table.pyreads that file directly (--uefn-since=<timestamp>keeps one session).
Speed-up = native time / rewrite time (above 1 means the rewrite is faster). Median of 4 rounds, 10,000 calls per block.
On the BPVM, building a /UnrealEngine.com/Temporary/SpatialMath struct is what costs, not the math. Every vector3{...} of Temporary creates 3 strings (MakeLiteral("__verse_0x…_X")…), a TMap<string,bool> of the given fields, and calls SpatialMath_vector3$OverrideFactory before setting the fields (seen in the BPVM disassembly). The /Verse.org/SpatialMath vector3 (@import_as FVVector3) only sets its 3 fields. 10,000 constructions (experiments/struct_cost.verse):
| New VM | BPVM | |
|---|---|---|
Temporary vector3{...} |
14 ms | 190 ms |
Verse.org vector3{...} |
18 ms | 6.8 ms |
| user struct | 7 to 8 ms | 133 to 222 ms |
tuple (X, Y, Z) |
3.8 ms | 3.9 ms |
So anything that builds intermediate vectors gains a lot when rewritten:
| Rewrite | New VM | BPVM local | BPVM UEFN |
|---|---|---|---|
HomingStep (7 intermediate vectors) with (float, float, float) tuples |
4.71× | 32.09× | 17.99× |
HomingStep with the Verse.org vector3 |
0.97× | 19.29× | 8.29× |
A + B with tuples |
2.94× | 25.65× | 17.78× |
DistanceSquared, without V2 - V1 |
3.08× | 22.97× | 14.56× |
V.IsFinite[], returns V instead of rebuilding it |
2.86× | 15.18× | 13.37× |
GetLocalForward, constant axis |
2.15× | 18.54× | 11.76× |
Concatenate, one pass instead of recursive Slice |
0.61× | 6.32× | 11.04× |
Distance, without V2 - V1 |
2.95× | 13.85× | 7.98× |
ReflectVector, without its 3 intermediate vectors |
2.42× | 3.68× | 3.93× |
MakeUnitVector |
1.67× | 2.22× | 2.37× |
C++ natives stay faster for scalar math. No Verse rewrite comes close: Sqrt 0.08×, Sin/Cos/Tan ~0.1×, Exp/Ln/hyperbolics ~0.05×, Floor/Round 0.04×, Abs 0.27×, Mod 0.40×, generic SortBy 0.71× (all BPVM UEFN).
UEFN confirms the local BPVM. 103 of 107 comparisons get the same verdict; the other 4 are borderline (Min/Max float, Insert, TransformVectorNoScale). Large gains are a bit smaller in UEFN, losses are the same. The UEFN run's checksum matches the local one bit for bit.
On the new VM the gaps mostly disappear. Verse.org vectors are on par with Temporary ones and tuples gain 2.5 to 5×, so this is mostly a BPVM matter for now.
What it means for hot UEFN code:
- Compute with tuples, or at least with
/Verse.org/SpatialMath, rather than/UnrealEngine.com/Temporary/SpatialMath. - If an API needs a Temporary
vector3, build it once, at the end. - In a long loop, suspend now and then (
Sleep(0.0)): the BPVM transaction keeps every allocation until it commits. - Keep the natives for scalar math.
- Effects (
<computes>,<reads>,<transacts>) do not change speed. On the BPVM,set Arr += array{X}is expensive (~15 µs),set Arr[I] = Xis almost free.
- Real runtimes. The new VerseVM and the BPVM were built from Unreal Engine source (pin
de57436d4d), with/Verse.org/SpatialMathand/UnrealEngine.com/Temporary/SpatialMathand their original C++ natives, plus aPROFILE <tag>: <ms> msline for everyprofileblock. Absolute times differ from Fortnite's; only the native/rewrite ratio on one VM matters. - Drop-in rewrites. Every rewrite in
bench/libis plain Verse with the same signature and effects as its native, and compiles in UEFN as is. - Same results. Before timing,
bench/harnesscompares each rewrite with its native on edge cases (NaN, ±Inf, -0.0, subnormals, failures of<decides>functions) and random inputs: 96 check groups, no divergence on the three runtimes. Gaps are 0 ulp, exceptFastSqrt(≤ 1 ulp), degree/radian conversions (≤ 1 ulp, up to 7 ulp on a rotated vector) and transcendentals (≤ 3 ulp). - Timing. Each block times 10,000 calls (arrays: 100 operations on 1,000 elements, 25 for
ConcatenateandReplaceAll; sorting: 50 sorts of 200 floats), 4 rounds, median. Inputs are built once, outside theprofileblocks. - UEFN. The same files run from a Verse device in a UEFN session, with
Sleep(0.0)between blocks to stay under UEFN's ~10 s limit for code that runs without suspending.
| Path | Contents | In UEFN |
|---|---|---|
bench/lib |
the rewrites: FastMath, FastArray, FastSpatial, FastVerseSpatial, TupleMath, FastTranscendental, FastSort, FastEasing |
as is |
bench/harness |
Check* (correctness), Bench* (profile blocks), inputs, RunCheck / RunBench |
in the same folder as lib |
bench/cli |
Main for the local runtimes |
no |
bench/uefn |
bench_device: the same calls from OnBegin |
yes |
experiments |
struct construction cost, SpatialMath smoke test | no |
tools |
launcher, UEFN sync, results table and page | no |
results |
raw/ profile lines of each runtime, table.json, the results page |
no |
Profile tags are Native <Name> and <Variant> <Name> with Fast, Inline, Inlined, VerseOrg, Tuple or Scalar as variant.
Write the rewrite in bench/lib, add bench/harness/bench_<name>.verse with a Check<Name> and a Bench<Name>, and give each one an index in RunCheck and RunBench (bench/harness/all.verse). Keep each RunBench item under ~2 s on the local Shipping BPVM so it stays under UEFN's limit.
NaN = NaNandNaN <= NaNsucceed;NaN < X,NaN > XandNaN <> NaNfail.- The BPVM keeps
-0.0(literals, storage, natives) but=does not tell it from0.0; the new VM turns everything into+0.0. The checks compare zero signs throughArcTan(X, -1.0). The nativesSqrt,AbsandTanreturn+0.0for-0.0. Clamp(float) returns NaN as soon as an argument is NaN, despite its@doc.FastClampreproduces the real behavior.Floor,Ceil,RoundandInton a float outside the 64-bit integer range raise a runtime error, not a failure.ArcSin(NaN)returns π/2 andArcCos(NaN)returns 0: the native clamps its argument to [-1, 1].- Rounding without a native call:
(X + 6755399441055744.0) - 6755399441055744.0(to nearest, ties to even, |X| < 2^51). - A local
varis not allowed in<computes>, hence the recursion inFastSqrt. Instantiating a class makes a function at least<transacts>. - Overloading a function on two option types (
?vector2/?vector3) is rejected as ambiguous. - Naming a variable like a
/Verse.org/Versefunction (Round,Floor,Abs,Min…) is an ambiguity error. - In UEFN a
usingonly applies to its own file; in a single concatenated file a top-levelusingalso applies inside modules, hence theverse_vector3/verse_rotation/verse_transformaliases. VerseCLRcannot call a<suspends>target directly, so the launcher startsMainwithspawn{}; on the new VM a file with@editablefields cannot run.- On Windows, editing
.versefiles with PowerShell 5.1Get-Content/Set-Contentbreaks UTF-8 and the compiler fails with V3100.
- Verse (UEFN, new VerseVM, BPVM)
- Bash and a Windows batch launcher through WSL
- Python for the results table and page generator
- HTML results page