Godotwright Game Optimizer
by laaielichter
README.md
<p align="center">
<a href="https://laaielichter.github.io/godotwright-gameoptimizer/"><img src="docs/assets/banner.svg" alt="Godotwright Game Optimizer: find what slows your Godot 4 game, fix it, prove it with a benchmark" width="100%"></a>
</p>
<p align="center">
<a href="https://github.com/laaielichter/godotwright-gameoptimizer/actions/workflows/ci.yml"><img src="https://github.com/laaielichter/godotwright-gameoptimizer/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"></a>
<img src="https://img.shields.io/badge/Godot-4.3%2B-478cbf?logo=godotengine&logoColor=white" alt="Godot 4.3+">
<img src="https://img.shields.io/badge/node-20%2B-339933?logo=node.js&logoColor=white" alt="Node 20+">
<img src="https://img.shields.io/badge/MCP-server-7c3aed" alt="MCP server">
<img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="Zero dependencies">
</p>
<p align="center">
<a href="https://laaielichter.github.io/godotwright-gameoptimizer/"><b>Website</b></a> ·
<a href="#quick-start">Quick start</a> ·
<a href="#the-loop">The loop</a> ·
<a href="#new-in-030">New in 0.3.0</a> ·
<a href="#install-for-your-agent">Install</a> ·
<a href="#tools">Tools</a> ·
<a href="#in-ci">In CI</a> ·
<a href="#measured">Measured</a> ·
<a href="#limits">Limits</a>
</p>
# Godotwright Game Optimizer
**Find what makes a Godot 4 game slow, fix it, and prove the fix with a benchmark.** An MCP server and CLI for
coding agents (Claude Code, Codex, Gemini CLI, Cursor, VS Code) and the developers who work with them. Made for heavy
open worlds; the 2D, audio, script, load-time and export rules apply to every game.
- **Finds the problem from the files.** The audit needs no Godot. On the 19 368-node demo world it takes under a
second.
- **Fixes it, reversibly.** World streaming, visibility ranges, light fades, texture and audio compression, quality
tiers, physics interpolation, the shader baker, a floating origin. Every change is journaled; `undo` restores
every byte.
- **Proves it.** The same camera route before and after: frame times, hitches, draw calls, memory, a pixel
comparison of every screenshot, and what bounds the frame. A fix that does not win is undone.
- **Keeps it fast.** `check` fails the pull request that breaks a budget and puts the findings on it as SARIF.
By [laaielichter](https://github.com/laaielichter). MIT. Node 20+, zero dependencies, no build step.
Part of the **Godotwright** family: [Godotwright](https://github.com/laaielichter/Godotwright) keeps your agent's Godot
code correct, the Game Optimizer makes the game fast. [Use them together](#use-it-with-godotwright).
**Add it to your agent** (more clients and options under [Install](#install-for-your-agent)):
| Client | How to add it |
| --- | --- |
| Claude Code | `/plugin marketplace add laaielichter/godotwright-gameoptimizer`, then `/plugin install gameoptimizer@godotwright-gameoptimizer` |
| Codex | `codex mcp add gameoptimizer -- npx -y github:laaielichter/godotwright-gameoptimizer mcp` |
| Gemini CLI | `gemini extensions install https://github.com/laaielichter/godotwright-gameoptimizer` |
| Cursor | [Add to Cursor](https://cursor.com/en/install-mcp?name=gameoptimizer&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsImdpdGh1YjpsYWFpZWxpY2h0ZXIvZ29kb3R3cmlnaHQtZ2FtZW9wdGltaXplciIsIm1jcCJdfQ%3D%3D) |
| VS Code | [Install in VS Code](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522gameoptimizer%2522%252C%2522type%2522%253A%2522stdio%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522-y%2522%252C%2522github%253Alaaielichter%252Fgodotwright-gameoptimizer%2522%252C%2522mcp%2522%255D%257D) (Copilot agent mode) |
Then ask your agent: *"Optimize my Godot game and prove each fix with a benchmark."*
<p align="center">
<img src="docs/assets/audit.svg" alt="Terminal output of gameoptimizer audit on the demo world: score 7/100, high findings such as 16k identical meshes as separate nodes and 260 lights that never fade out, each with a fix command, and the plan." width="100%">
</p>
## Quick start
Try it on the heavy demo world in under a minute, no Godot needed:
```sh
npx -y github:laaielichter/godotwright-gameoptimizer demo ./world
npx -y github:laaielichter/godotwright-gameoptimizer audit ./world
npx -y github:laaielichter/godotwright-gameoptimizer costmap ./world
```
What `audit` prints on the demo (trimmed, paths shortened):
```text
Open World Demo (Godot 4.7, forward_plus, 27 files, 2 scripts)
world/world.tscn: 19368 nodes, 17837 mesh instances (11 unique), 0 multimesh instances, 4846k triangles, ...
worst view: 4787k triangles, 17403 surfaces in range (cells of 128 m)
textures: 7, about 28 MB of VRAM
score 7/100 high 4 medium 7 low 5
HIGH 16k identical meshes are separate nodes (5 kinds) [world/repeated-mesh-nodes]
fix: gameoptimizer fix instancing ./world --scene world/world.tscn
HIGH 14k small objects are drawn at any distance [world/no-visibility-range]
fix: gameoptimizer fix ranges ./world --scene world/world.tscn
HIGH 260 of 260 omni and spot lights never fade out (260 cast shadows) [world/lights-without-distance-fade]
fix: gameoptimizer fix lights ./world --scene world/world.tscn
HIGH One scene holds a 2400 m world with 17k placed objects [world/monolithic-scene]
fix: gameoptimizer fix partition ./world --scene world/world.tscn
...
Plan:
1. Install the runtime kit (quality tiers, governor, streamer, spawn queue, prewarm, probe)
gameoptimizer fix install ./world (safe)
2. Write the recommended project settings
gameoptimizer fix settings ./world (safe)
3. VRAM-compress and mipmap the textures used in 3D, then re-import
gameoptimizer fix textures ./world (reimport)
...
Measure first: gameoptimizer bench --label baseline. After each step: bench --label <name>, compare <name>.
```
Every finding carries its evidence (nodes, files, lines) and the command that fixes it. On your own game:
`audit path/to/project`. To let your agent run the whole loop, [add the MCP server](#install-for-your-agent).
<p align="center">
<img src="docs/assets/costmap.svg" alt="World cost map of the 2.4 km demo world: 16 by 16 cells, hot in the centre, with eight numbered benchmark stations on a dashed route. Worst view 4.8 million triangles." width="70%">
</p>
## The loop
Audit, fix one step, benchmark, compare. Keep what wins, undo what does not.
```text
optimizer_status where am I, and the next call no Godot
optimizer_audit findings + plan no Godot
optimizer_bench label=baseline frame times, hitches, draws, memory, screenshots, what bounds the frame
optimizer_fix fix=<step> one step of the plan (dry_run to preview)
optimizer_bench label=<step>
optimizer_compare run=<step> better / same / worse, picture same / changed, which part moved
keep it, or optimizer_undo
optimizer_check budgets in CI (exit 1 on a fail) no Godot
```
On the CLI the same steps are `status`, `audit`, `bench --label baseline`, `fix <step>`, `bench --label <step>`,
`compare <step>`, `undo` and `check`.
Keep a fix only when `compare` says "improvement, picture unchanged". On "mixed" (faster at p50, slower at p99) or
"more hitches", look at the hitches, then tune or undo. When the picture was not compared (fly mode, headless, no
display), measure both runs in `stations` mode with a display first. The bound of the baseline says which steps
matter: when the frame is GPU-bound, settings and textures matter more than nodes; when it is CPU-bound in
rendering, ranges, instancing and partition do. The audit's plan marks those steps.
## New in 0.3.0
The five biggest changes. The full list is in the [CHANGELOG](CHANGELOG.md).
1. **What bounds the frame.** The probe splits every frame into script, physics, CPU rendering and GPU time.
`bench` names the bound per station and over the run (`gpu`, `cpu-render`, `script`, `physics`, `vsync`, or
`unknown` with the reason, such as headless or a software renderer) and the fixes that matter most for it.
`compare` says which part a fix moved, and which part to cut next.
2. **Export rules and the `export` fix.** The audit flags presets without the shader baker on Godot 4.5+ (Forward+
and Mobile), scripts exported as text, files the game loads that a preset leaves out, and unused files a preset
still packs. `fix export` turns on the shader baker and compressed binary scripts in `export_presets.cfg`, and
nothing else.
3. **Physics feel.** The audit finds interpolation off while scripts move bodies below 120 ticks (judder on 120 to
165 Hz screens), the default cap of 8 steps per frame with 100 or more moving bodies, and cameras that copy a body
in `_process`. `fix physics` turns interpolation on and, with `max_steps`, sets the cap.
4. **GOOrigin, a floating origin.** `fix origin` adds it under the world scene's root. Past 2 km from the origin the
world moves back by whole cells in one physics frame. Bodies keep their velocity, streamers keep what they loaded.
5. **GOStreamer generator sources.** A world your code builds can now stream:
`streamer.register_source(&"terrain", 64.0, build_cell, release_cell)` builds each cell on a worker thread as it
comes in range, with the same frame budget, radii and prediction as chunk scenes.
Also new: budgets, a findings baseline and SARIF in [`optimizer_check`](#in-ci), `optimizer_status`,
`optimizer_history`, `optimizer_report`, `optimizer_unused`, `target` (desktop, mobile, web, Steam Deck, VR), the
Claude Code plugin and the Gemini CLI extension.
## What it solves
Godot 4 renders beautifully, but a large world runs into the same walls every time. Each row is a problem the
engine leaves to you, and what this tool does about it.
| Problem in Godot 4 | What the optimizer does |
| --- | --- |
| **No world streaming.** A scene is loaded, instantiated and kept in memory as a whole. | `partition` cuts a world scene into chunk scenes on a grid. **GOStreamer** loads them around the camera on a thread, attaches nodes within a per-frame time budget and loads ahead of the camera's movement. |
| **No HLOD.** Unload a chunk and its buildings vanish from the skyline. | Every chunk gets a **stand-in scene**: one MultiMesh per mesh of only the parts large enough to be seen from far, with no physics, lights or scripts. It is drawn while the chunk is not loaded, so the picture stays the same. |
| **Only a far plane.** A pebble 2 km away is still an instance to cull. | `ranges` gives every object a visibility range computed from its own size on screen (invisible below 6 pixels by default), and takes tiny objects out of the shadow passes. |
| **A MultiMesh is culled as one box.** One MultiMesh for a forest is always drawn in full; a node per blade of grass drowns the scene tree. | `instancing` merges identical meshes into **one MultiMesh per world cell**, each with its own visibility range. A trade (see Measured): the plan marks it optional unless the node count is high. |
| **No texture streaming.** Every texture of a loaded scene sits in VRAM in full; projects built outside the editor never get VRAM compression. | `textures` sets VRAM compression and mipmaps for the textures 3D materials use (4 to 8 times less memory). Streaming then makes texture memory follow what is loaded. |
| **No dynamic resolution, no quality presets.** Project settings are read at start. | **GOQuality**: five tiers (low to cinematic) applied at run time: FSR 1/2 and scale, AA, shadows, GI, SSAO, SSR, fog, LOD bias. **GOGovernor** holds a target frame rate by moving the resolution scale, then a ladder of settings. |
| **Hitches from main-thread loading.** `load`, `instantiate` and `add_child` block the frame. | **GOSpawnQueue** loads on a thread and attaches within a time budget. The audit finds the loops that do it the slow way. |
| **Shader compilation stutter** for content that arrives after the loading screen. | **GOPrewarm** draws every material and vertex format once behind the loading screen. The probe counts pipeline compilations per frame on Godot 4.4 and newer, so you can see it work (Godot 4.3 has no counter for them: there the count stays 0). |
| **Lights that never switch off.** Every shadowed omni light renders the scene six times. | `lights` sets distance fade from each light's range; optional dual-paraboloid shadows. |
| **The world is built from code**, or the game only exists as a `.pck`: there is no scene file to read. | The **live census** starts the game, lets the world build and counts what is really in the tree: nodes per script that made them, repeated meshes, a mesh or a material per object, objects without a visibility range, textures that sit uncompressed in VRAM, nodes that process every frame. **GOWorldPolicy** then gives every mesh and light a visibility range, shadow rule and distance fade as it enters the tree. |
| **A world built from code does not stream.** There are no chunk scenes to load. | A GOStreamer **generator source** (`register_source`) asks your code for a cell's nodes on a worker thread as the cell comes in range, and attaches them within the frame budget. |
| **Precision falls apart far from the origin.** 32-bit positions jitter from about 8 km. | `origin` adds **GOOrigin**: 2 km out, the world moves back by whole cells in one physics frame. Bodies keep their velocity, streamers keep what they loaded. |
| **Is it the GPU or the CPU?** Godot's process time is the slowest frame of the last second, rendering included. | `bench` splits every frame into script, physics, CPU rendering and GPU time and says per station what bounds it; `compare` says which part a fix moved. |
| **Judder on 120 Hz screens.** Bodies move on 60 Hz physics ticks. | The audit finds motion on ticks with interpolation off, and a step cap that lets one slow frame slow the next. `physics` turns interpolation on and sets the cap. |
| **Every player compiles every shader** on the first launch of the exported game. | `export` turns on the shader baker (Godot 4.5+) and binary scripts in `export_presets.cfg`. |
| **Where is it slow?** You find out by flying around. | The **world cost map** predicts triangles, draw calls and shadowed lights per cell from the files, finds the hotspots and writes a benchmark route through them. |
| **Did the optimization break the look?** | `bench` takes a screenshot at every station; `compare` checks them pixel by pixel next to the numbers. Runs use a fixed time step, so the sun and animations are in the same state in both. |
| **A pull request makes it slower**, and nobody notices. | `check` fails the CI job when a budget breaks and puts the findings on the pull request as SARIF. |
| **Importing on a machine without a GPU hangs** on VRAM-compressed textures (the GPU compressor runs on a software driver). | `import` and `bench` select the CPU compressor for the length of the import. |
Everything an agent changes is journaled: `undo` restores every byte.
## Install for your agent
The server speaks MCP over stdio. One command, no install step:
```sh
npx -y github:laaielichter/godotwright-gameoptimizer mcp
```
**Claude Code plugin**: the server, four skills, the `game-optimizer` subagent and `/gameoptimizer:perf-check`.
```text
/plugin marketplace add laaielichter/godotwright-gameoptimizer
/plugin install gameoptimizer@godotwright-gameoptimizer
```
It asks for the Godot project folder and the Godot 4 binary; both are optional. Claude uses the skills on its own,
or you start them: `/gameoptimizer:optimize` (the measured loop), `/gameoptimizer:stutter` (hitches and loading),
`/gameoptimizer:vram` (memory and export size) and `/gameoptimizer:ci` (budgets and SARIF). See
[the plugin's README](plugins/gameoptimizer/README.md). For the server alone:
```sh
claude mcp add gameoptimizer -- npx -y github:laaielichter/godotwright-gameoptimizer mcp
```
**Gemini CLI extension**: the server, [GEMINI.md](GEMINI.md) and the `gameoptimizer` skill.
```sh
gemini extensions install https://github.com/laaielichter/godotwright-gameoptimizer
gemini extensions config godotwright-gameoptimizer GODOT # optional: the Godot 4 binary, for measuring
```
**Cursor** (one click): [Add to Cursor](https://cursor.com/en/install-mcp?name=gameoptimizer&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsImdpdGh1YjpsYWFpZWxpY2h0ZXIvZ29kb3R3cmlnaHQtZ2FtZW9wdGltaXplciIsIm1jcCJdfQ%3D%3D)
**VS Code** (Copilot agent mode, one click): [Install in VS Code](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522gameoptimizer%2522%252C%2522type%2522%253A%2522stdio%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522-y%2522%252C%2522github%253Alaaielichter%252Fgodotwright-gameoptimizer%2522%252C%2522mcp%2522%255D%257D) · [VS Code Insiders](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522gameoptimizer%2522%252C%2522type%2522%253A%2522stdio%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522-y%2522%252C%2522github%253Alaaielichter%252Fgodotwright-gameoptimizer%2522%252C%2522mcp%2522%255D%257D), or from a terminal:
```sh
code --add-mcp '{"name":"gameoptimizer","type":"stdio","command":"npx","args":["-y","github:laaielichter/godotwright-gameoptimizer","mcp"]}'
```
**Codex**: `codex mcp add gameoptimizer -- npx -y github:laaielichter/godotwright-gameoptimizer mcp`, or in
`~/.codex/config.toml`:
```toml
[mcp_servers.gameoptimizer]
command = "npx"
args = ["-y", "github:laaielichter/godotwright-gameoptimizer", "mcp"]
```
**Windsurf, Cline and other MCP clients** (`mcpServers` in their JSON config)
```json
{
"mcpServers": {
"gameoptimizer": {
"command": "npx",
"args": ["-y", "github:laaielichter/godotwright-gameoptimizer", "mcp"]
}
}
}
```
On Windows, if `npx` does not start from the client: `"command": "cmd", "args": ["/c", "npx", "-y", ...]`.
**Which project.** A call that names no `project` uses `GAMEOPTIMIZER_PROJECT`, else the folder the server runs in.
The plugin and the extension set it from their settings; elsewhere put it in the server's environment:
`GAMEOPTIMIZER_PROJECT=~/games/forest npx -y github:laaielichter/godotwright-gameoptimizer mcp`.
**No MCP?** Every tool is a CLI command with `--json`. [AGENTS.md](AGENTS.md) and [llms.txt](llms.txt) describe the
loop; [skills/gameoptimizer](skills/gameoptimizer/SKILL.md) is the same as an agent skill. Over MCP the server also
offers resources (the loop, the skill, the runtime API, `gameoptimizer://explain/{topic}`) and five prompts:
`optimize`, `fix-stutter`, `reduce-vram`, `optimize-for-mobile`, `ci-budget`.
Measuring needs Godot 4 (4.3 or newer; developed against 4.7.2): pass `godot` or set `GODOT`. A path that does not
exist or cannot run is an error; it never falls back to another godot on the PATH. The audit, the cost map, `check`
without measured budgets and every fix work without Godot.
## Tools
Sixteen tools. Each is also a CLI command (`gameoptimizer <command> --json`); `gameoptimizer tools` prints their
input schemas.
| Tool | CLI | What it does |
| --- | --- | --- |
| `optimizer_status` | `status` | Where the project stands in the loop: Godot found, the runtime kit current, the journal, the runs, a baseline, `.gameoptimizer` git-ignored. `next` is the one call to make now, ready to run: a run after a fix repeats the baseline's launched scene, mode, route, time step, renderer, resolution, tier and headless, and it says keep only on "improvement, picture unchanged". `--baseline` names the baseline run (default: `baseline` or a run whose label ends in it, such as `fly-baseline`: the one the newest run was measured like). Reads files only. |
| `optimizer_audit` | `audit` | Findings with evidence and the plan. Reads scenes, models, textures, audio, import files, settings, export presets, scripts and shaders. `target`: `mobile`, `web`, `steamdeck` or `vr` (default `desktop`). `cell_size` sets the cost-map cells (metres). |
| `optimizer_costmap` | `costmap` | Predicted cost per world cell, hotspots, a text picture of the map, a benchmark route. |
| `optimizer_census` | `census` | Starts a scene (project or `--pack game.pck`), lets it build, counts the live tree and reports findings. For worlds built from code. |
| `optimizer_textures` | `textures` | GPU memory per texture, largest first. |
| `optimizer_unused` | `unused` | Files nothing refers to, by folder with their size. Read-only; `--exclude-filter` gives the `export_presets.cfg` line that keeps them out of the build. |
| `optimizer_fix` | `fix <name>` | `install`, `policy`, `settings`, `physics`, `export`, `textures`, `audio`, `lods`, `lights`, `ranges`, `instancing`, `partition`, `origin`. `dry_run` supported. |
| `optimizer_undo` | `undo [id] [project]` | Takes a fix back: the latest entry, or the journal entry `id` (a whole number in the journal; anything else is an error). `--list` shows the journal. Refused when a later fix touched the same files or uses what this one created (undo that one first), or when a file the fix wrote was edited since (`--force` overwrites those edits). A refusal is an error (exit code 2, `isError` over MCP) that says why; nothing is undone. |
| `optimizer_bench` | `bench` | Runs the game with the probe: percentiles, hitches with position and cause, monitors, draw calls per pass, screenshots, and what bounds the frame at each station. `stations` or `fly`. |
| `optimizer_compare` | `compare <run>` | Baseline against a run, per metric, per station and per screenshot, and which part of the frame the fix moved. Exit code 1 on a regression. |
| `optimizer_history` | `history` | Every benchmark run, oldest first, with the change of p50, p99, draw calls and video memory against the baseline. |
| `optimizer_check` | `check` | The budgets in `gameoptimizer.json`, pass or fail, with a findings baseline and SARIF. Exit code 1 on a fail. See [In CI](#in-ci). |
| `optimizer_report` | `report` | One Markdown page for a pull request: the audit, the fixes, the runs and the last comparison. `--write` saves `.gameoptimizer/report.md`. |
| `optimizer_import` | `import` | Godot's import, also on machines without a GPU. `ok: false` with the reason when Godot fails. |
| `optimizer_explain` | `explain <topic>` | Why a finding costs performance in Godot, how the fix works, what to check after. Takes a topic or any finding id. |
| `optimizer_demo` | `demo <dir>` | Writes the heavy open-world demo project. `--force` overwrites one and first removes what earlier runs left. |
| Fix | What it changes |
| --- | --- |
| `install` | Adds the runtime kit (`addons/gameoptimizer`) and its autoloads. |
| `policy` | GOWorldPolicy: culling rules for nodes that scripts create at run time. |
| `settings` | The recommended project settings for the `target`. |
| `physics` | Physics interpolation on; with `max_steps`, a cap on physics steps per frame. Risk: gameplay (call `reset_physics_interpolation()` after teleports). |
| `export` | The shader baker (Godot 4.5+) and compressed binary scripts in `export_presets.cfg` (`preset` for one), nothing else. |
| `textures`, `audio`, `lods` | `.import` files: VRAM compression and mipmaps for 3D textures (`size_limit` caps them), Quite OK Audio for WAV files of `min_seconds` (10) or more (IMA-ADPCM before 4.3), mesh LODs. Re-import after. |
| `lights`, `ranges` | Distance fade for lights (`paraboloid` for cheaper omni shadows); visibility ranges from each object's size (`pixels`), tiny shadow casters off. |
| `instancing`, `partition` | Repeated meshes into one MultiMesh per cell; the world scene into streamed chunks with stand-ins (needs `install`). Structural: commit first. |
| `origin` | A GOOrigin node under the world scene's root (needs `install`); `threshold` is the shift distance (2000 m). |
## What the audit looks at
- **World**: repeated meshes as separate nodes, repeated scene instances, objects without a visibility range, tiny
shadow casters, lights without distance fade, cube-shadow omnis, several shadowed suns, sun shadow distance, heavy
meshes, CSG in levels, no occluders, heavy particle systems, trimesh colliders, body counts, content far from the
origin (float precision), one scene holding a whole world, far plane without fog, SDFGI, probes that update every
frame.
- **Textures and models**: 3D textures without VRAM compression or mipmaps, oversized textures, textures embedded
in models, models imported without LODs.
- **Settings**: occlusion culling, VRAM compression, anisotropic filtering (where a material or shader uses it),
debanding, physics engine, culling thread threshold, MSAA with temporal AA, native high resolution without an
upscaler, physics tick rate, uncapped frame rate, shadow atlas size. The physics thread is advice only: with it on,
Godot allows physics queries in the physics process only. Every path was checked against the Godot 4.7 class
reference.
- **The running game** (`census`): the same world rules on the live tree, plus a mesh or a material per object,
uncompressed and run-time textures, nodes that process every frame, tree size, SubViewports that always update,
canvas item counts, trimesh faces, distance from the origin. Every row names the script that built the nodes.
- **Scripts**: whole-tree searches from the root, time tests that stay true for a window of frames, label text
set every frame, textures made from images at run time, node lookups and `load()` on per-frame paths, a
`MeshInstance3D` or a material per object in a loop, `instantiate()` in loops, collision built from meshes in
loops, mesh generation on the main thread, `print` every frame, arrays allocated every frame. Main-thread stalls:
texture data read back from the GPU, files read, parsed or written every frame, `OS.delay_msec` outside a thread.
Per-frame waste: `connect()` and timers every frame, nodes made and freed instead of pooled, physics queries in
loops, `get_pixel`/`set_pixel` in nested loops. Only code that runs on each call of a per-frame callback counts
(not under an `if`, not after a throttling return); editor-only code and test suites are skipped. This is where
worlds built from code show up.
- **Shaders**: screen and depth reads, `discard` without a depth prepass, long texture loops.
- **Audio**: WAV files of 10 s or more imported as uncompressed PCM (about 10 MB per minute of stereo), WAV files
Godot's importer refuses or imports as silence (with the reason and an ffmpeg command), many AudioStreamPlayer3D
nodes without `max_distance`.
- **Materials**: alpha blending on many instances, identical materials saved as separate resources, double-sided
opaque materials on closed meshes.
- **Environment** (Forward+): two or more of SSR, SSIL, volumetric fog and SDFGI without quality tiers, a volumetric
fog buffer above 64x64x64, SSR above 128 steps, VoxelGI at 512 subdivisions with its GPU memory.
- **2D**: shadowed 2D lights over occluders, deprecated `TileMap` nodes and TileMaps with many layers, thousands of
static sprites that could be a TileMapLayer or MultiMesh, a material copy per canvas item that breaks batching.
- **Physics, navigation and animation**: continuous collision on many bodies, areas that are both monitoring and
monitorable, masks on all 32 layers, many avoidance agents, navigation baked per frame or on the main thread,
animation trees and players that run off screen. Physics feel: interpolation off while scripts move bodies or
cameras below 120 ticks (judder on 120 to 165 Hz screens; 2D from Godot 4.3, 3D from 4.4), many moving bodies with
the default cap of 8 steps per frame, cameras that copy a body's position in `_process`.
- **Load time and export**: what loads before the first frame (the main scene and the autoloads, with the chain that
pulls each heavy file in), autoloads that keep many MB for the whole run, files the game loads that an export
preset leaves out, unused files that an export still packs, presets without the shader baker on Godot 4.5+, and
presets that ship scripts as text.
- **Targets** (`target`): the renderer phones, browsers and headsets run and the effects it lacks, ETC2/ASTC import,
textures over 2048 px on mobile, lights per mesh over the Mobile and Compatibility limits, occluders on the web,
native resolution on the Steam Deck, temporal AA and foveation with MSAA in VR. `export_presets.cfg` is evidence
only; it never changes the target.
- **The runtime kit**: installed but no quality tier ever applied; the audit names the findings that stay quiet
because of it.
## In CI
`optimizer_check` turns "it got slower" into a failing check on the pull request that made it slower. It reads
`gameoptimizer.json` next to `project.godot`; with `$schema`, editors complete and check every key:
```json
{
"$schema": "https://raw.githubusercontent.com/laaielichter/godotwright-gameoptimizer/main/gameoptimizer.schema.json",
"target": "desktop",
"ignore": [{ "id": "world/no-occluders", "reason": "indoor levels only" }],
"budgets": { "score_min": 60, "high_max": 0, "texture_vram_mb_max": 1500, "frame_ms_p99_max": 20 }
}
```
- Static budgets need no Godot: `score_min`, `high_max`, `medium_max`, `findings_max`, `texture_vram_mb_max`,
`view_triangles_max` and `view_draws_max` (the worst cell of any audited scene), `scene_nodes_max`.
- Measured budgets read a `bench` report (`--run`, default the baseline, else the newest): `frame_ms_p50_max`,
`frame_ms_p99_max`, `hitches_max`, `draw_calls_max`, `video_mem_mb_max`, `nodes_max`. Without a report they are
skipped, never passed; `--require-measured` makes them fail, for a job that must benchmark.
- `ignore` takes finding ids, prefixes (`script/*`) and a `file` glob; ignored findings leave the score and the plan.
`--budgets high_max=0,score_min=80` overrides the file for one run.
- `check --save-baseline` writes today's findings to `gameoptimizer.baseline.json`. Commit it with
`gameoptimizer.json`: `--new-only` then counts only findings that are not in it, so an old project can adopt
budgets without fixing everything first.
- `--sarif gameoptimizer.sarif` writes SARIF 2.1.0 with paths from the git repository root, so a Godot project in a
subfolder works (`--sarif-root` names another root).
- Exit code 0: every budget passed. 1: a budget failed. 2: an error in the input or in `gameoptimizer.json` (a wrong
key or type is an error, never a silent default).
```yaml
# .github/workflows/performance.yml
name: Performance budget
on: pull_request
permissions:
contents: read
security-events: write
jobs:
budget:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npx -y github:laaielichter/godotwright-gameoptimizer check . --new-only --sarif gameoptimizer.sarif
- uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: gameoptimizer.sarif
category: gameoptimizer
```
Drop `--new-only` until a baseline is committed. Code scanning is free on public repositories; without it, drop the
upload step and the check still fails the job. "Export all resources" packs `.json` files, so add
`gameoptimizer*.json` to the export preset's exclude filter. `optimizer_report` writes the same numbers as Markdown
for the pull request. The [ci skill](plugins/gameoptimizer/skills/ci/SKILL.md) has the whole setup.
## The runtime kit
`fix install` copies `addons/gameoptimizer/` into the game and registers its autoloads. Plain GDScript, no
GDExtension, Godot 4.3+.
```gdscript
GOQuality.apply_tier(GOQuality.auto_detect()) # low, medium, high, ultra, cinematic
GOQuality.set_value("scaling_3d_scale", 0.67) # one key, for a settings menu
GOGovernor.start(60) # hold 60 fps with dynamic resolution
GOSpawnQueue.instantiate_async("res://enemy.tscn", parent, func(node): ...)
await prewarm.run(["res://world/world_chunks/Town/c_0_0.tscn"]) # GOPrewarm, behind the loading screen
streamer.register_source(&"terrain", 64.0, build_cell, release_cell) # GOStreamer: cells your code builds
origin.origin_shifted.connect(_on_origin_shifted) # GOOrigin: move the positions your scripts keep
```
`GOStreamer` nodes are placed by `partition`; a generator source streams a world your code builds. GOOrigin (a
floating origin) is added by `origin`. The full API is in
[runtime/addons/gameoptimizer/README.md](runtime/addons/gameoptimizer/README.md).
## Worlds built from code
```sh
gameoptimizer census path/to/project # or: --pack game.pck
gameoptimizer fix policy path/to/project
gameoptimizer census path/to/project --label after
```
On the demo built by a script (`gameoptimizer demo /tmp/w --procedural`, 1 101 mesh instances) the first census
reports 1 100 objects without a visibility range, 300 materials used by one object each and a 1024 px texture made
at run time, all traced to `world_builder.gd`. After `fix policy` the second census counts 1 object without a range
(the ground), no tiny shadow casters and no lights without a fade.
To stream such a world, wrap the code that builds one cell in a GOStreamer generator source:
`streamer.register_source(&"terrain", 64.0, build_cell, release_cell)`. `build_cell(cell: Vector3i) -> Node` runs on
a worker thread; the streamer attaches its nodes within the frame budget and gives them back when the cell leaves.
See the [runtime kit README](runtime/addons/gameoptimizer/README.md#worlds-built-from-code-generator-sources).
## Use it with Godotwright
[**Godotwright**](https://github.com/laaielichter/Godotwright) ([website](https://laaielichter.github.io/Godotwright/))
is the coding toolkit for Godot agents: the real Godot 4.7 API offline, a scored review of every script that catches
Godot 3 habits, scenes that merge in git, and `bisect` to find the commit that broke it. Godotwright makes sure what
the agent writes is right; the Game Optimizer makes sure it runs well. Both are MCP servers, so one agent can use both:
```sh
claude mcp add godotwright -- npx -y godotwright mcp
claude mcp add gameoptimizer -- npx -y github:laaielichter/godotwright-gameoptimizer mcp
```
A good order: `godotwright review` until the scripts are clean, then `optimizer_audit` and the measure-fix-compare loop.
## Measured
Two runs on the demo world (`gameoptimizer demo`), every number from `bench` and `compare`. The machine is a
4-core container without a GPU: rendering is Mesa's software Vulkan driver (llvmpipe), so milliseconds only compare
with each other. Counts and memory are exact.
**The 2.4 km world, 19 371 nodes, flown through headless** (script, scene and streaming cost, no rendering):
| | Before | After `install settings textures lights ranges partition` |
| --- | ---: | ---: |
| Frame time p50 (CPU side) | 8.19 ms | **1.31 ms** |
| Frame time p99 | 19.66 ms | **5.31 ms** |
| Hitches during the flight | 66 | **5** |
| Nodes in the tree (max) | 19 371 | **7 877** |
| Static memory | 91 MB | 85 MB |
**A 900 m world, rendered at 8 stations**, step by step, each compared with the step before:
| Step | Nodes | Objects drawn | Draw calls | Picture | Verdict of `compare` |
| --- | ---: | ---: | ---: | --- | --- |
| baseline | 3 127 | 2 033 | 117 | | |
| settings, textures, lights, ranges | 3 130 | 1 658 | 99 | changed on purpose: mipmaps end the shimmer | better |
| + partition with stand-ins | 1 662 | 810 | 335 | **same** (0.4% of pixels) | fewer nodes and culled objects; more draw calls |
| instancing instead (tried, undone) | 928 | 422 | 264 | **same** (0.0%) | regression on this renderer: undone |
What the numbers say, without rounding in our favour:
- Forward+ already draws identical meshes in a handful of draw calls (2 033 objects in 117 calls). Merging them
into MultiMeshes, by `instancing` or in stand-ins, removes nodes and culling work but adds draw calls and culls
more coarsely. On a software renderer that cost more frame time than it saved (+13%); on a GPU a few hundred
draw calls are cheap and the CPU side is what the first table shows. That is why the tool measures, and why
`instancing` is marked optional. Measure on your target and keep what wins there.
- The picture comparison caught three real mistakes while this tool was built (a too-early light fade, forest
chunks unloaded too soon, a day cycle that made runs incomparable). That gate is in every `compare`.
- With streaming, video memory rose by 40 MB at one point: the omni shadow atlas, which Godot allocates the first
time a shadowed lamp is drawn.
Reproduce: `gameoptimizer demo /tmp/world`, then [the loop](#the-loop).
**Before and after, station 2 of a 900 m world** (1280x720, Godot 4.7.2, same machine, run on 28 November 2026), the
safe steps only: `install settings textures lights ranges`.
| Before | After |
| --- | --- |
|  |  |
| Over all 8 stations | Before | After | |
| --- | ---: | ---: | --- |
| Draw calls (avg) | 133 | 111 | -16% |
| Objects drawn (avg) | 3 804 | 3 205 | -16% |
| Texture memory (max) | 200 MB | 177 MB | -11% |
| Video memory (max) | 221 MB | 202 MB | -8% |
| Frame time p50 (software renderer) | 629 ms | 672 ms | **+7%, worse** |
`compare` called this run a regression, and it was right to: on the software renderer the frame time went up. We
have not isolated the cause; texture filtering with mipmaps, which a CPU rasterizer pays for in full, is the likely
suspect (the 16x anisotropic level that `settings` wrote in this run does not apply to the demo's materials, which
use the default filter). The picture changed on purpose (up to 6% of pixels): mipmaps end the moire on the
ground and in the leaves. On a GPU, measure again and keep what wins there.
## Limits
- The audit reads text scenes and resources (`.tscn`, `.tres`) and glTF models. Binary `.scn` and `.res` files are
counted but not opened.
- A world built entirely from code has no scene to partition. `census` shows what the code builds and which
script builds it, `fix policy` culls it at run time, and the script rules point at the loops; merging nodes into
MultiMeshes is then a change in that code, and streaming it takes a GOStreamer generator source around the code
that builds one cell.
- Stand-ins cover plain meshes, with the node's material override, overlay, shadow mode and layers; hidden meshes
get none. Models placed as `.glb` scenes, skinned meshes, MultiMeshes, meshes whose surfaces have different
material overrides and anything with a light that still shines beyond the load radius stay real nodes in far
chunks.
- `instancing` leaves nodes alone that have a script, a group, children, a connection or a NodePath pointing at
them. `partition` leaves a container's child in the world scene when a connection or a NodePath points at it,
when it holds a unique name (`%Name`) or a NodePath that points out of it, or when it holds another streamed
container. Nodes with a script or a group move with their chunk. Code that finds moved nodes by path has to change.
- Occluders are not baked for you (Godot bakes them in the editor); the audit says when they are missing.
- Visibility distances assume a 75° field of view at 1080p; `pixels` and the tiers' `lod_bias` scale them.
- These need Godot 4.3+: `bench`, `census`, `import` and the measured budgets of `check`. The shader baker bakes
when you export, from an editor that runs the preset's renderer (Direct3D 12 needs a Windows editor, Metal a
macOS one). GOOrigin moves the world, not the positions your scripts keep: those follow `origin_shifted`.
- Without a GPU, frame times come from a software renderer and only compare with each other; `bench` then says the
bound is `unknown (software renderer)`, and headless runs say `unknown (headless)`. Trust draw calls, nodes and
memory there.
- Godot 3 projects are refused: convert them in Godot 4 first.
## Contributing
Issues and pull requests are welcome. A finding that was wrong on your project, or a `compare` report from a real
GPU, helps the most. Start with [CONTRIBUTING.md](CONTRIBUTING.md); [AGENTS.md](AGENTS.md) has the layout and the
rules, and issues marked `good first issue` are a good place to begin.
```sh
npm test # no dependencies, no Godot
GO_TEST_GODOT=1 npm test # also runs the runtime kit and a full optimize-and-measure in Godot
node scripts/sync-version.mjs # after a version change in package.json: server.json, the plugin, the extension
```
If the optimizer saved you a profiling session, a star helps other Godot developers find it.
## License
MIT, see [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityNo data
ResponsivenessOutdated data