Performance measurement
Measure CPU time, GPU cost and memory in the embedding title, and see how Aperture UI saves work on each frame and which tools show where the time goes.
Measure tick(), command-list construction and GPU submission separately in the host profiler.
Record SDK revision, build flavor, hardware, viewport, content and capture date with every result.
A frame budget belongs to the title and must be measured on target hardware. A game UI runs inside a frame budget that the whole game shares. A browser can spend a long time on one layout pass and nobody notices. A game cannot. Aperture UI's job is to do as little work as it can on each frame. Yours is to decide how much of the frame the UI gets and to keep the page inside it.
These pages make no benchmark claims and publish no timings. A number measured on one machine with one page says little about yours. They describe how the engine saves work and how to avoid giving that work back, and the tools below measure the rest.
- Rendering: inspect layout, draw state, layers and texture use.
- Scripting: reduce repeated compilation and unnecessary mutations.
Where the time goes
A frame of UI has the same phases whatever the page:
| Phase | What drives its cost | Read about it |
|---|---|---|
| JavaScript | Event handlers, timers, requestAnimationFrame callbacks, bridge calls | Scripting |
| Style | The number of dirty elements and how rules are matched | Style |
| Layout | The dirty elements, their ancestors and the layout mode | Layout |
| Paint | How much of the tree changed, and how many layers it needs | Paint and Layers |
| Command generation | The number of visible elements and text runs | Draw calls |
| Your GPU | Draw calls, overdraw, off-screen targets and texture uploads | Layers |
view->tick(dt) advances time and runs script. Pending style and layout run when something needs
them: before paint, in view->buildCommandList(), or earlier if script reads a computed style or a
geometry value. The biggest single factor is how many elements are dirty. The engine restyles, lays
out and repaints only what a change touched, so a page that changes a little each frame is cheap,
and a page that rebuilds everything each frame is not.
What the engine does for you
| Mechanism | What it saves | Default |
|---|---|---|
| Subtree restyle | A class, attribute or inline-style change restyles the changed element's subtree, not the document. | On |
| Parallel style | A large restyle is spread across worker threads, one tree level at a time. | On |
| Incremental layout | Layout visits the dirty elements and their ancestors and reuses clean subtrees. | On |
| Paint-only changes | A script change confined to paint-only properties skips layout. | On |
| Scroll frames | A frame where only scroll offsets changed reuses the previous paint tree. | On |
| Draw batching | Commands with identical state merge into one draw. One geometry upload per submit. | On. A backend can also opt into draw records. |
| Layer targets | Off-screen targets are sized to their content, and an unchanged layer keeps its target. | On |
| Caches | Tessellated geometry, shaped text, decoded images and shared SVG icons. | On |
| Script | Compiled-script caching and bytecode caching, JSON calls that compile nothing, and a tier-up budget. | Some are opt-in |
Rendering explains each of these and how to work with them.
The switches that exist are SDK settings, set on aperture::ApertureSDK before you create views
(see SDK settings): SetParallelStyleEnabled,
SetIncrementalLayoutEnabled and SetGeometryUploadCacheEnabled. A title can turn off a mechanism
at run time to compare, or to rule it out while chasing a bug.
Measure it
In your game
The two calls to time are tick() and buildCommandList():
const auto t0 = clock::now();
view->tick(deltaSeconds);
const auto t1 = clock::now();
const auto& commands = view->buildCommandList();
const auto t2 = clock::now();
// Feed (t1 - t0) and (t2 - t1) to your own profiler.If tick dominates, look at script and at style and layout work. If buildCommandList dominates,
look at paint, layers and text. The time your render context spends drawing the list is a separate
number, in your own GPU profiler.
Environment probes
These variables switch on log output from the engine. They exist in the engine source without a
build-configuration guard, so the Shipping and PartialCore builds in the SDK package read them too.
Set them in the environment of the process before it starts. A platform that cannot set environment
variables cannot use them.
| Variable | Set it to | What it logs |
|---|---|---|
APUI_PROF_SLOW | 1 | A [PROF] warning for each style and layout flush that takes longer than a fixed threshold, split into style, counters, animation, layout, scrollbar retry and scroll dimensions. A slow layout pass also reports how many elements were dirty, affected, laid out and skipped. |
APUI_JS_PROF | 1 | About every two seconds, a [JSPROF] warning: scripts run, compile time, run time, garbage-collection time, direct function calls and their cost, and script-cache hits and misses. |
APUI_BATCH_STATS | any value | For every submit, the commands in, the draw batches out and the geometry size. Also printed to stderr. |
APUI_LAYER_DEBUG | any value | A line for every layer render target acquired, with its size. |
APUI_V8_FLAGS | V8 flags | Not a probe. The text is appended to the flags V8 starts with. See Scripting. |
APUI_PROF_SLOW and APUI_JS_PROF are read by the engine itself. APUI_BATCH_STATS and
APUI_LAYER_DEBUG are read by SimpleAPHIRenderContext, so they apply to a backend derived from
it (see Rendering backends). The finer per-phase layout
counters that follow the first line of a slow layout report are filled in only by Debug and Dev
builds.
The output goes through the engine's log. A debugger attached to the process shows it. To get it into
your own log, turn on SetInternalEngineLogging(true) and install a forward callback as shown in
Your own C++ host.
Tracy
The engine has profiler zones and per-frame plots for Tracy. They exist only in Debug and Dev
builds on Windows, where both NS_USE_PROFILING and TRACY_ENABLE are set. A Shipping build
compiles them out, on purpose: Tracy opens a listening socket in any build that has it, and the
operating system's firewall would report a shipped game as using the network. If your package is a
Shipping package, which its MANIFEST.md states, there is nothing for Tracy to connect to. Profile
with a development build of the engine.
DevTools
The included Windows SDK DevTools server can record layout, style recalculation, paint and script events when your host starts and ticks it. JavaScript debugging and CPU/heap profiling use the V8 inspector in V8 builds. See DevTools.
Habits that keep a UI cheap
- Build the DOM once and change state, instead of rebuilding structure every frame.
- Change a little, often, in small subtrees, and batch your writes before you read.
- Animate
transformandopacity, not layout properties. - Keep the number of off-screen layers down: each opacity, filter and blend-mode group is one.
- Push data to the page when it changes, in one call, and not on every tick.
- Remove players and elements you no longer need. A hidden Lottie player keeps running.
Test the Real Thing
Include repeated screen transitions and long sessions in memory tests, and watch process memory over time as well as frame time. Test the shipping SDK and your own renderer backend rather than projecting browser performance onto the game: a page that is fast in a browser can still be slow in yours, and the other way round.
Web platform support
The HTML, CSS and JavaScript test corpus pages that Aperture UI renders and compares with Chrome, listed with their status.
Rendering performance
What a change costs in style, layout and paint, how layers and draw calls work, and how to keep text, images and effects cheap in Aperture UI.