Files
Eagler-Archive/incari-client/files/docs/adr/0064-teavm-0-16.md
T

96 lines
5.2 KiB
Markdown

# ADR 0064: TeaVM 0.16.0
- Status: accepted
- Date: 2026-10-20
## Context
TeaVM 0.16.0 (2026-10-02) is mostly C backend work, but it also fixes several of the bugs
`tools/teavm-patches` carried for the browser build, adds class library methods, makes some
WebAssembly GC code faster, and ships WebGPU bindings. The patches are copies of TeaVM's own
classes, so each one was merged onto 0.16.0's source (three-way, with 0.15.0 as the base) and
checked by hand.
## Decision
Pin TeaVM 0.16.0 (and its jzlib 1.1.3, unchanged).
**Patches dropped**, 0.16.0 having the same fix: `WasmTypeInference`, `TThrowable`, `Heap`,
`WasmGCInstructionGenerationVisitor`.
**Patches cut down** to what 0.16.0 still lacks:
| Class | Still ours | Now TeaVM's |
| --- | --- | --- |
| `CoroutineTransformation` | Nullable block types; nullable locals | The type after a suspending `c ? a : b` |
| `WasmGCSupertypeFunctionGenerator` | Binary search of tag ranges (ADR 0026) | `instanceof Item[]` |
| `TByteBufferImpl`, `TByteBufferNative` | Absolute `getLong(int)` keeps the position | Absolute bulk `put` |
| `TCollections` | `unmodifiableCollection` lookups | `unmodifiableSet` and `unmodifiableMap` lookups |
| `TDefaultPath` | `resolve` | `iterator`, `equals` |
**Patches rebased** with the fix unchanged: `TTemplateCollections`, `ReflectionMetadataGenerator`,
`Fiber` (`Fiber.Jspi`), `TObject`, and the rest as they were. The probes that guarded the dropped
patches still run, now guarding TeaVM's fixes.
**A new patch: the coroutines' fiber checks.** 0.16.0 has every coroutine call
`Fiber.isPresentAndSuspending(fiber)` after each call that may suspend, and
`isPresentAndResuming(fiber)` in its prologue, where 0.15 called `fiber.isSuspending()` and
`fiber.isResuming()`. The new ones accept a null fiber, which takes a test and a branch: twice the
code. Profiles of the lobby showed the game's own small methods (`ChunkPos.isValid`,
`LevelHeightAccessor.isInsideBuildHeight`, `getMaxY`, `ItemStack.isEnchanted`) no longer inlined
into their callers, their bodies unchanged: V8 spends its inlining budget on the checks first. The
Compatible build was 17% slower in the lobby. `CoroutineFunctions` (with `WasmGCDependencies`
linking the instance methods) goes back to 0.15's checks. The game runs coroutines only on fibers,
so the fiber is never null there. Reading the field in `isPresentAndSuspending` instead of calling
`isSuspending` won back only half; typing coroutine values as 0.15 did (no `forceNullable`) won
nothing.
**Using what 0.16.0 adds:**
- `web-classlib`: `RandomAccessFile.read()` is TeaVM's own (it now reads bytes unsigned);
`LocaleAdditions` uses `Locale.of`.
- `WebGpuCallProbe` uses `org.teavm.jso.webgpu` (`GPUDevice`, `GPUBindGroup`,
`GPURenderPassEncoder`) and record-style `@JSProperty` getters. It keeps one overload TeaVM's
binding lacks: `setBindGroup` with a range of the offsets array, without which each draw would
allocate a subarray.
- With no code: `Math.min`/`max` as WebAssembly instructions, `getEnumConstants` cached
(`Enum.valueOf`, `EnumSet`, `EnumMap`), `System.getLogger` (Via's snakeyaml now links it instead
of having it removed).
Not taken: the C backend, Maven toolchains. Nothing in the survey's rules covered what 0.16.0 adds.
**Found on the way, fixed here:** `buildManifest` could hash the module while `teavm` was still
writing it, in the same run (`mustRunAfter` now orders them). The page then had a manifest for the
last build, and a benchmark's cold start right after a compile never reached its first frame.
And `checkDownloadSize` failed before measuring: three loader scripts had no classification, and
two limits were already passed (`index.html` with its inline images, the pack with Incari's own
textures and fonts); they're raised in `download-budget.properties`, which says why.
## Results
The desktop (Ryzen 5 9600X, RX 9060 XT), CPU throttled 4x as a stand-in for the floor laptop,
which was down. Release builds; CPU a frame is tick + extract + render submit; means of runs.
| Build | Runs | Flythrough (ms) | Combat (ms) | Lobby (ms) | Lobby fps | Warm start (s) | Join (s) |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| Compatible, 0.15.0 | 3 | 5.15 | 5.04 | 33.07 | 27.8 | 9.75 | 21.9 |
| Compatible, 0.16.0 without the fiber checks | 3 | 5.54 | 5.73 | 38.55 | 24.3 | 10.08 | 21.4 |
| Compatible, 0.16.0 | 2 | 5.03 | 5.20 | 32.59 | 27.9 | 9.68 | 19.9 |
| Fast, 0.15.0 | 2 | 3.51 | 3.14 | 17.89 | 50.8 | 7.83 | 16.4 |
| Fast, 0.16.0 | 2 | 3.28 | 2.96 | 17.68 | 51.8 | 7.73 | 15.6 |
Two runs of one build differ by up to 12% in flythrough and combat and 6% in the lobby, so 0.16.0
is as fast as 0.15.0, not measurably faster. Memory is unchanged (lobby live heap 361 against
362 MB).
The modules grew: Compatible 66.3 to 68.2 MB raw (21.7 MB gzip), Fast 33.0 to 34.7 MB. Not broken
down; by its source, 0.16.0 gives nearly every class a supertype function, where 0.15 gave one only
to classes something tested against, and its field metadata grew for `Field.get*`/`set*`. Well
inside the budget (40 MB gzip).
## Left for later
- Report upstream: the fixes still in `tools/teavm-patches`, and the fiber checks' cost to inlining.
- `FileInputStream.read()` still reads bytes signed, and `RandomAccessFile`'s `"rw"` still
empties the file; `web-classlib` still covers both.