Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

perf(render): per-frame glGetError polling is opt-in, not a tax

esenginec892519fdba6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ffc94fb3f..013002180 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -171,6 +171,15 @@ to.
and the order between a C++ system and the JS-owned registry is not guaranteed.
Held by an AddressSanitizer harness that exercises both orders.
+- **The renderer no longer interrogates the GPU about errors it isn't having.**
+ Every frame ended with a drain of `glGetError` — a debug facility that shipped
+ enabled, in every build, on every platform. Each call is a synchronous round
+ trip to the GPU process; on a fast machine it hides, and on a slow or contended
+ one it was the single largest item in the renderer's profile, starving the
+ editor's automation surface into timeouts. Error checking is opt-in now
+ (`GLDebug.enable()`), the on-demand probes still force a check, and the browser
+ already reports WebGL errors to the console on its own.
+
- **Saves no longer live in a directory the platform may delete.** Key/value
storage went to the host's cache directory, whose stated purpose was the
regenerable bytecode cache. On iOS that is `NSCachesDirectory`, which the system
diff --git a/desktop/scripts/editor-mcp.mjs b/desktop/scripts/editor-mcp.mjs
index 0dc8f39aa..2b2f482eb 100644
--- a/desktop/scripts/editor-mcp.mjs
+++ b/desktop/scripts/editor-mcp.mjs
@@ -104,6 +104,12 @@ function spawnHost(mode, token) {
command = createRequire(import.meta.url)('electron');
args = mode === 'editor' ? ['.', '--mcp'] : [path.join(HERE, 'editor-mcp-host.mjs')];
}
+ // Extra Chromium/Electron switches for a diagnostic run (dev only) — e.g.
+ // ESTELLA_MCP_EDITOR_ARGS='--remote-debugging-port=9333' to let a debugger
+ // reach the renderer of an editor a script is driving.
+ if (process.env.ESTELLA_MCP_EDITOR_ARGS) {
+ args.push(...process.env.ESTELLA_MCP_EDITOR_ARGS.split(/\s+/).filter(Boolean));
+ }
const host = spawn(command, args, {
// An installed exe needs no cwd (and the repo layout may not exist there).
cwd: editorExe ? undefined : DESKTOP,
diff --git a/src/esengine/bindings/EngineState.hpp b/src/esengine/bindings/EngineState.hpp
index f1de375dd..813a59776 100644
--- a/src/esengine/bindings/EngineState.hpp
+++ b/src/esengine/bindings/EngineState.hpp
@@ -11,7 +11,13 @@ struct EngineState {
int webgl_context = 0;
bool initialized = false;
bool immediate_draw_active = false;
- bool gl_error_check_enabled = true;
+ // Off by default: glGetError is a SYNCHRONOUS round-trip to the GPU process,
+ // and the per-frame drain (renderer_flush/renderer_end) pays it on every
+ // frame of every shipped game. Under a slow or contended GPU process those
+ // round-trips starve the renderer's event loop — measured as the editor's
+ // automation surface timing out while `getError` topped the profile. Opt in
+ // via GLDebug.enable(); gl_checkErrors() probes force a check regardless.
+ bool gl_error_check_enabled = false;
u32 viewport_width = 1280;
u32 viewport_height = 720;
glm::vec4 clear_color{0.0f, 0.0f, 0.0f, 1.0f};