Hazel

Benchmarking the Editor

cargo renzora bench profiles the staged engine on a project with nobody at the keyboard, then reports where the frame time went. It saves runs under names so a change can be measured against the build before it. It runs the same profiler as the companion's Profiler screen and the MCP profiler_* tools, so its numbers read the same way.

cargo renzora bench --project C:/Users/me/Documents/my_game --save before
# ...make a change, then `cargo renzora dist`...
cargo renzora bench --project C:/Users/me/Documents/my_game --compare before

Options

FlagDefaultWhat it does
--project <dir>requiredThe project to open. The project itself is never touched: a copy is made under target/bench/work/ for each run.
--seconds <s>10How long to record.
--settle <s>5How long to wait after the project has opened before recording, so shader compilation, asset streaming and first layout are over.
--save <name>Keep this run as target/bench/saved/<name>/. Saving under an existing name replaces it.
--compare <name>Print this run beside a saved one: frame times, every schedule, and the systems that moved by 0.02 ms or more.
--scenario <file>Work through a list of steps, each changing the scene and recording on its own. See Scenarios.
--sampleoffRecord call stacks too (see Call-stack sampling). Off by default so timings compare cleanly from run to run; it costs about 5% of the frame rate. Setting RENZORA_SAMPLE_HZ yourself overrides both.
--no-pluginsStart with no native plugins, to measure the engine alone.
--buildRun cargo renzora dist first. Without it the bench uses whatever is already staged in dist/.

What a run does

  1. Copies the project, because opening one in the editor writes to it (the layout, thumbnails, and on Play the open scene).
  2. Starts the staged renzora with --bench <out>. With the editor image beside it this is the editor, the usual case. The window is a normal 1920x1080 window placed off every screen, kept out of the taskbar, with vsync and the frame cap off. The editor's "throttle when unfocused" setting is ignored, so it doesn't matter which window has focus while the bench runs.
  3. When the project has reached the editor, the engine waits for --settle, takes start.png, records for --seconds, takes end.png, writes the capture and exits. If the project has not opened after 180 seconds, the run fails and the engine writes error.txt.
  4. Runs renzora-companion --analyze over the capture and prints a short summary.

Everything for the newest run is in target/bench/last/:

FileWhat it is
capture.rcapThe recording. Open it in the companion's Profiler screen to see every frame.
analysis.jsonThe full analysis: summary (what the MCP profiler_summary tool gives), spikes (the slowest frames) and median_frame (the median frame laid out by thread, with each schedule's critical path).
summary.txtThe lines the bench prints.
start.png, end.pngWhat the window showed when recording started and when it ended, to check that the project actually opened.
memory.txtThe memory breakdown (assets by kind, images on the GPU by source, GPU allocations by label) taken when recording ended. The load report in the log is taken when loading finishes; anything created after that, while settling or recording, shows only here.
cameras.txtEvery camera when recording ended, active ones first, with its order, kind, target, target size and name. Bevy gives each active camera with a target of its own a full set of frame textures, so this says whose the main_texture and view_depth sets in memory.txt are.
run.jsonThe run's settings and frame count.
compare-<name>.txtWith --compare, the comparison it printed.

Scenarios

A plain run measures the project as it opens. A scenario measures it under several settings in one run: each step changes something, waits for it to settle, records, and screenshots either end. Changes build on the steps before them.

settle = 4      # seconds after each step's changes (default 3)
seconds = 6     # seconds recorded per step (default: --seconds)

[[step]]
name = "baseline"

[[step]]
name = "ssil off"
set = [{ entity = "world_environment", component = "SsilSettings", field = "enabled", value = false }]

[[step]]
name = "solari on"
settle = 25     # a step can set its own settle and seconds
set = [{ entity = "world_environment", component = "SolariGi", field = "enabled", value = true }]

[[step]]
name = "no world environment"
despawn = ["world_environment"]
  • set writes one field. The entity is found by its name, the component by its short type name, and the field by a dotted path such as ssao.enabled or translation.x: the same addressing scripts use. A value is a boolean, a number, a string, or an array of 3 or 4 numbers.
  • despawn removes entities by name.
  • A change that cannot be made (a misspelt name, a field that is not there) is logged and listed in run.json, and the run carries on.

Each step writes its own folder, <NN>-<name>/, holding the same files as a plain run. The bench prints one line per step. --save keeps the whole set, and --compare compares each step with the step of the same folder name in the saved run.

A scenario names entities in one particular project, so it lives with your own files rather than in the engine repository. target/bench/scenarios/ is a convenient place: it is ignored by git and sits beside the runs. To measure the editor with nothing in it, finish with a step that despawns everything in the scene.

The machine around the frame

Every profile, from the bench, the companion or the MCP tools, also records what the machine was doing, as counters sampled four times a second:

CounterWhat it says
CPU: this process (cores)CPU time the engine used per second, so 2.5 is two and a half cores busy on average.
CPU: other processes (cores)The same for every other program. Above about one core, absolute times from the run are suspect, and the bench prints a warning.
CPU: whole machine (%)How busy all the cores were together.
RAM: working set (MB), RAM: committed (MB)Memory the engine holds in RAM, and memory it has committed. Committed climbing through a still scene is a leak.
RAM: page faults (per s)
GPU memory: allocated (MB), GPU memory: reserved (MB), GPU memory: allocationsWhat wgpu's allocator has handed out, the memory blocks it holds, and how many allocations. Measured once a second on a thread of its own, since building the report on the render thread would show up as a stall in the same profile.
GPU memory by label (MB): <label>The twelve resource labels holding the most GPU memory, each summed over its allocations. Bevy leaves many resources unlabelled; they add up under (unlabelled).
GPU objects: <kind>Live textures, texture views, buffers, bind groups, samplers and render pipelines, from wgpu's resource registry. wgpu sizes every render pass's, compute pass's and submit's resource tracker to the device's whole range of texture and buffer indices, so every live texture and buffer costs every pass some render-thread CPU, used by that pass or not. Textures and buffers are in the headline and in --compare.
Thread CPU (%): <thread>How much of the time each recorded thread was running on a core.
Thread waiting for a core (%): <thread>Linux only: time the thread was ready to run but had no core.

Process CPU and memory are measured on Windows and Linux. summary.counters gives each counter's mean, least and most over the run, so growth or a busy spell partway through shows. The bench prints the means under the frame times, and --compare lists them under machine: a run that is slower everywhere while another program's CPU use went up is the machine, not the change.

Each entry in summary.gpu_passes also carries what Bevy measures for that pass beyond its GPU time:

  • cpu_encode_ms: the render thread's time recording the pass's commands.
  • vertices, fragments, compute_invocations: shader invocations a frame, where the GPU supports pipeline statistics.

A pass that is slow for the number of pixels it shades is limited by fill rate; one slow for its vertex count is limited by geometry.

Allocations per system

The engine's global allocator counts every heap allocation per thread, and the profiler stamps each span's start and end with the count. summary.allocations lists the spans that allocate most per frame (per_frame, kb_per_frame), children included, as span times are. The bench prints the top ones, and --compare lists every span whose allocations moved by five a frame or more.

The counter lives in the shared contract image, so it sees the engine binary, the editor, the contract, the UI framework and native plugins. It cannot see allocations made inside Bevy's own image, which is built before it: a Rust dylib uses the allocator it was linked with, so Bevy's non-generic internals go uncounted. Generic Bevy code (a Vec growing, a query collected, Commands) is compiled into the crate that uses it and is counted there. A lean export links everything into one binary, and there the count is complete. Counting costs a thread-local addition per allocation and is always on.

Frees are counted the same way. Each entry also has frees_per_frame and net_kb_per_frame, what the span kept: a system that allocates a lot and frees it all is churn, one with a positive net every frame is growing something.

Live large allocations

While a profile records, every allocation of 64 KB or more is remembered with the call stack that made it until it is freed. Once a second the profiler groups the ones still alive by stack, and summary.live_memory lists the largest groups at the end of the run (mb, count, age_s, and from, the first frames outside the allocator), with the total at the start and at the end. Growth between the two with the scene unchanged is memory something keeps. The bench prints the three largest.

Call-stack sampling

A span says which system took the time, not what inside it did. On Windows the profiler reads every thread's call stack 250 times a second while recording (RENZORA_SAMPLE_HZ changes the rate; 0 turns sampling off). The bench turns it off unless you pass --sample; a profile recorded through the editor samples by default. On the bistro scene that rate costs about 5% of the frame rate and a quarter of a core for the sampler thread; 1000 Hz cost about 15%. Compare runs recorded with the same setting. A thread that has not run since its last sample is not stopped again: its previous stack is reused and marked waiting, and a thread that has been idle a while is looked at only every 10 or 50 ticks. Each sample counts for the time since its thread's previous one, so the slower looks still add up to the right time.

Stacks are unwound from a copy taken while the thread is suspended for a few microseconds. The engine does not name them: it sends the raw addresses with its list of loaded modules, and the companion names them from the PDBs, live or when it reads a bench capture. Naming inside the engine took most of a core for the first seconds of a session and about half a gigabyte of memory, all of it in the profile. The PDBs are found from the path each binary records, beside the binaries, then on the engine's RENZORA_SYMBOL_PATH, then on _NT_SYMBOL_PATH. The bench points RENZORA_SYMBOL_PATH at target/dist, where cargo leaves the PDBs; set it yourself for a profile recorded through the editor if dist/ has no PDBs. A bench capture holds raw addresses, so analyse it with the build that recorded it; a capture saved from the companion window is already named.

summary.sampling holds:

KeyWhat it says
functionsWhere running threads were, by self time (the innermost frame), with the inclusive time beside it.
functions_inclusiveEvery function by inclusive time.
systemsFor each system, the functions that ran inside it and what it waited on.
outside_systemsPer thread, CPU spent in no system, by function. callers lists every function on those stacks, so the executor, the event loop and the render handoff show by name. This is what explains a high cpu_outside_spans_percent.
waitingPer thread, time not running, by what the stack was blocked in: a lock, the GPU or driver, disk or network, a sleep, window events, an idle task pool, or a channel, condvar or park.
locksLock waits, by the function that took the lock and the system it was in. This is lock contention.

The dist profile builds without debug info, so PDBs name only each crate's exported functions; a private function reads as (unnamed function at +0x...) with its offset in the module rather than borrowing a neighbour's name. Building with debug = "line-tables-only" in the dist profile names every function, adds inlined functions as frames of their own and gives each frame its file and line. --compare lists sampled functions whose self time moved by 0.05 ms a frame or more.

Context switches and hardware counters

Run as administrator on Windows, the profiler also starts a kernel trace session while recording and keeps every context switch of the engine's threads: exactly when each was put on a core and taken off, which core, and why it left. summary.context_switches gives each thread's exact on_core_percent, switches_per_frame, cores_used, and off_core, the time off a core by reason: preempted when it could have run but another thread had the core, otherwise the wait reason. Without administrator rights the session is refused, the log says so once, and the waits from the samples above are the estimate.

Where the CPU and Windows allow it, the same session reads the CPU's counters at every switch, and each frame carries per-thread counters for the twelve busiest threads: Thread cycles (M), Thread instructions (M), Thread IPC, Thread cache misses (K), Thread branch mispredicts (K). They appear in summary.threads. Instructions per cycle well under 1 means the thread spends much of its time stalled, usually on memory.

Log lines and pictures

Log lines written while recording travel with the frame they were written in. summary.log counts them by level and lists the warnings and errors, the same line counted once with how often it came. The timeline marks each one under the ruler.

Four times a second the profiler also keeps a picture of the window, 320 pixels wide, so a slow frame can be matched to what was on screen.

Waiting versus working

A system can be slow because its code is slow, or because its thread was not running: blocked on a lock, the GPU or the disk, or pushed off its core by another thread or program. Spans cannot tell those apart. summary.threads sets each thread's time inside systems (in_spans_percent, not counting the spans that wrap whole schedules and worlds) beside its time on a core (cpu_percent). off_core_percent is the gap one way: at least that much of the time the thread was inside a system without running. cpu_outside_spans_percent is the gap the other way: CPU spent outside any system, on the executor scheduling systems and checking run conditions, the event loop, or a task pool looking for work. The bench names any thread with either gap at 10% or more.

Background tasks

Renzora's own background work (scene parsing, thumbnails, Solari's ray tracing proxies, script builds and scans, virtual geometry conversion, terrain bakes, environment map conversion) runs on Bevy's async and I/O pools under a span named task: <what it is>, entered each time the task runs. Each one appears on its pool thread in the timeline, with its time and allocations, so loading and baking work shows up beside the frame it competes with.

In the companion

The Profiler screen's right-hand panel opens with a Machine section: small graphs of the engine's and other programs' CPU use, committed RAM, GPU memory, page faults and allocations a frame over the recorded frames, and the focused frame's heaviest allocators. Each thread row shows its share of a core beside its work bar.

Below it are the picture of the window nearest the focused frame, the sampled functions and waits in the timeline's view (zoom onto one system to see what ran inside it), and the log lines in view. A function whose samples carry a file and line is a link: clicking it opens the source around that line, read from disk.

Benching a shipped game

A game runs the same profiler, so --bench <dir> works on an exported binary too, with --bench-seconds and --bench-settle as the bench passes them. It records once its first frame is up, the settle covering its loading. To compare a game with the editor on one project:

  1. Copy the project somewhere under target/ and make any changes there, not in the real one.
  2. Open the copy once with cargo renzora bench --project <copy>, so its Rust scripts compile. The libraries land under target/bench/work/<copy name>/.renzora/scripts/<stem>/.
  3. Pack it: cargo run --profile dist -p renzora_rpak --example pack_game -- <copy> <out>/<name>.rpak. That runs the export's packing steps (referenced files, editor-only components stripped, compression level 3), without plugins or the Files tab.
  4. Beside the archive, put dist/<platform>/renzora.exe renamed to <name>.exe, the *_dylib, std-* and openxr_loader libraries from the same folder, and for scripts scripts/script_<i>.dll with a scripts/scripts.index of path<TAB>file lines (see Rust scripts).
  5. From that folder, RENZORA_SAMPLE_HZ=0 ./<name>.exe --bench <dir> --bench-seconds 30 --bench-settle 40, then renzora-companion --analyze <dir>/capture.rcap --out <dir>/analysis.json --text <dir>/summary.txt and --compare <editor run>/analysis.json <dir>/analysis.json --out <file>.

Match what the two runs draw before comparing them. The bench window is 1920×1080 for both, but the editor renders the scene only into its viewport (about 1437×932 in the default layout) while a game fills the window, so give the copy a render_scale that brings the scene to the same pixel count. A game also renders from its scene camera, and the editor from its own orbit camera, so put the scene camera where the editor's starts.

Why the window is off-screen and not hidden

A Windows window created hidden still renders and can still be screenshotted, but it measured about a quarter slower than a shown one: presenting to a window the compositor is not showing costs about half a millisecond more a frame. A bench run has to present the way the user's window does, so it uses a shown window placed at (-20000, -20000). The size is fixed so that two runs on one machine compare, whatever the monitor or the project's saved layout would pick. The engine moves the window back if the splash maximizes it or a layout moves it.

crates/renzora_profiler/examples/hidden_window.rs made the measurement and can repeat it on other platforms: cargo run --profile dist -p renzora_profiler --example hidden_window -- offscreen (or hidden, visible).

Reading a comparison

Two runs of the same build on the same machine usually differ by a few percent in frame time, and individual systems differ by a few microseconds. Before trusting a small change:

  • Run each side twice. If the two runs of one build differ by as much as the change you are measuring, the result is noise.
  • Close anything heavy. The bench measures the whole machine, including a build running in the background.
  • Compare p50 rather than mean, because one long frame can move the mean a lot.

The pieces

PieceWhere
The command-line flags and the window placementrenzora_diagnostics_api::bench
The window at creationrenzora_runtime::add_default_rendering
Recording, screenshots, keeping the window off-screenrenzora_profiler/src/bench.rs
CPU, per-thread CPU, memory and GPU memory countersrenzora_profiler/src/resources.rs
The counting allocatorrenzora_diagnostics_api::allocations
Allocations per spanrenzora_companion_proto::frame::SpanBuilder
Per-pass encode time and shader invocationsrenzora_profiler::gpu_passes
Call-stack sampling, the module list, live large allocationsrenzora_profiler/src/sampler/
Naming sampled addresses from the PDBsrenzora_companion_server/src/symbols.rs, capture::Capture::expand
Context switches and hardware countersrenzora_profiler/src/etw.rs
Pictures of the windowrenzora_profiler/src/images.rs
Log lines while recordingrenzora_diagnostics_api::profiling (drain_messages)
What the samples, switches, live memory and log sayrenzora_companion_server/src/sampling.rs
--analyze, --compare, --textrenzora_companion_server (main.rs, analysis::offline, analysis::compare)
The commandxtask/src/bench.rs
--no-pluginsrenzora_native_plugin::plugin_entries

The capture file is the same packet stream the engine sends a companion over its socket, written by a thread in the engine. Saved captures and live recordings are read by the same code.

See also