Skip to content

A field's limit counts letters, performance.now() stops with the machine, file reads leave the JavaScript thread, and a huge display list still draws - #12

Merged
explodi merged 5 commits into
mainfrom
from-vendored-mwf3txgd
Nov 13, 2026

Conversation

@explodi

@explodi explodi commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Five changes made in a game that vendors Bureau, one commit each:

  • A field's maxLength counts UTF-16 units, and the view's JSON survives a byte that is not UTF-8. Typed text was cut to the limit in bytes, so a letter such as é at the limit lost its second byte, JSON refused the field's value and the interface stopped. The limit now counts as the native text input's edits already did, and the view's JSON for JavaScript reads a stray byte as U+FFFD instead of throwing.
  • performance.now() is the time the machine was awake. It was std::chrono::steady_clock, which runs on through sleep on macOS and Windows, so a client could not tell a sleep from a stalled thread. It now reads the uptime clock on Apple, the unbiased interrupt time on Windows, and CLOCK_MONOTONIC as before on Linux and Android (src/js/awake_clock.h).
  • The host provides Uint8Array.fromBase64. Hermes has none, and a loop in its interpreter takes a quarter of a second over a megabyte of base64, all in one turn. The host installs a native one when the runtime has none, with the standard's alphabet and lastChunkHandling options and its errors.
  • A client's file reads leave the JavaScript thread, and a fallback face opens when a character needs it. assetText and assetBytes were synchronous calls that a slow disk held for seconds. The UI now reads on a thread of its own and answers on the interface's. The first label laid out also opened every face in the fallback chain, the 10 MB CJK faces among them; a fallback is now opened only when a character the faces before it lack needs it (Typesetter::Chain).
  • A display list of millions of quads draws what fits. A list of tens of thousands of cards made a vertex buffer the device refused, and the interface was lost. batchesOf leaves out a quad wholly outside its clip and stops at 128 MB of vertices (kMaxVertices), and every backend grows its vertex buffer by one shared rule capped there (vertexBufferBytes) and draws nothing for empty batches.

What a host must follow

  • __native.assetText(path, done) and assetBytes(path, done) take a callback instead of returning the file. The kit's platform (kit/native_platform.ts) wraps it in the promise it already returned, so a client that reads through the kit changes nothing; one that called __native itself must.
  • The asset reader a host gives Ui::Options is now called from two threads (the UI's, for the view's faces and pictures, and the UI's reading thread), so it must be safe to call from both.

Checks

  • The branch starts from eb1b47f, this repository's main. Staged with the game's bureau:vendor push, which ran deno install --frozen, deno fmt --check, deno lint, deno task check and deno task test here before anything was committed; the five commits add up to exactly the tree it staged.
  • The same sources pass Bureau's C++ suites on macOS in the game's checkout, where the Metal, OpenGL and Vulkan backends compile. The core and the JavaScript host, the awake clock's Windows, Linux and Android arms among them, compile in the game's Windows, Linux and Android builds; those arms were not run there.
  • Not compiled anywhere: src/backends/d3d11.cpp and d3d12.cpp build only on Windows, and neither this repository's workflow nor the game builds them (the game draws through a pass of its own). Each change there is an early return for empty batches and the buffer's size from vertexBufferBytes.

… a byte that is not UTF-8

Typed text was cut to a field's maxLength in bytes, so a letter such as é
at the limit lost its second byte, and JSON refused the field's value: the
interface stopped. The limit now counts UTF-16 units, as the native text
input's edits already did, and the view's JSON for JavaScript reads a byte
that is not UTF-8 as U+FFFD instead of throwing.
The host's performance.now() was std::chrono::steady_clock, which runs on
through sleep on macOS and Windows, so a client could not tell a sleep (the
wall clock ran on alone) from a thread that stalled. It now reads the uptime
clock on Apple, the unbiased interrupt time on Windows, and CLOCK_MONOTONIC
as before on Linux and Android (awake_clock.h).
Hermes has no ECMAScript 2026 Uint8Array.fromBase64, and a loop in its
interpreter takes a quarter of a second over a megabyte of base64, all of it
in one turn. The host installs a native one when the runtime has none, with
the standard's alphabet and lastChunkHandling options and its errors.
…e opens when a character needs it

assetText and assetBytes were synchronous calls on the JavaScript thread,
which a slow disk held for seconds. They now take a callback: the UI reads
on a thread of its own and answers on the interface's, so a host's asset
reader must be safe to call from both threads (Ui::Options). The kit's
platform wraps the callback in the promise it already returned.

The first label laid out opened every face in the fallback chain, the
10 MB CJK faces among them. A fallback face is now opened only when a
character the faces before it lack needs it (Typesetter::Chain).
…he GPU for more than it takes

A list of tens of thousands of cards made millions of quads, whose vertex
buffer the device refused, and the interface was lost. batchesOf now leaves
out a quad wholly outside its clip, as the scissor would discard it, and
stops at 128 MB of vertices (kMaxVertices): the topmost content goes rather
than the frame. Every backend grows its vertex buffer by one shared rule
capped there (vertexBufferBytes) and draws nothing for empty batches.
@explodi
explodi merged commit 462b761 into main Nov 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant