Profiler
The StatsPlugin provides real-time performance monitoring with an on-screen overlay showing FPS, frame time, rendering stats, and per-system timings.
Enabling the Profiler
Add StatsPlugin in your script’s setup function:
import { StatsPlugin } from 'esengine';
export function setup(app) { app.addPlugin(new StatsPlugin());}Configuration
new StatsPlugin({ overlay: true, // Show on-screen panel (default: true) position: 'top-left', // 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' container: document.body, // DOM parent for the overlay})| Option | Type | Default | Description |
|---|---|---|---|
overlay | boolean | true | Show the on-screen stats panel |
position | string | 'top-left' | Overlay position on screen |
container | HTMLElement | document.body | DOM parent for the overlay element |
Metrics
The overlay displays:
Performance
- FPS — frames per second, smoothed over a 60-frame window
- Frame time — average milliseconds per frame
Rendering
- Draw calls — number of draw calls per frame
- Triangles — total triangle count
- Sprites / Text / Spine / Meshes — rendered count per type
- Culled — entities skipped by frustum culling
World
- Entities — total entity count
Systems
- Top 5 slowest systems with average and peak execution time in milliseconds (displayed as
avg / max ms) - Stats are throttled to 500ms updates for stable readability without losing peak information
Reading Stats in Code
Access the Stats resource in your systems:
import { defineSystem, addSystem, Res, Stats } from 'esengine';
addSystem(defineSystem( [Res(Stats)], (stats) => { console.log(`FPS: ${stats.fps}`); console.log(`Draw calls: ${stats.drawCalls}`); console.log(`Entities: ${stats.entityCount}`); }));Frame History
FrameHistory is a utility class that maintains a rolling buffer for trend analysis. Create an instance and feed it data from the Stats resource:
import { FrameHistory, Stats, Res, defineSystem, addSystem } from 'esengine';
const history = new FrameHistory(300);
addSystem(defineSystem( [Res(Stats)], (stats) => { history.push(stats.frameTimeMs, new Map()); }));
// Get the most recent frame snapshotconst latest = history.getLatest();if (latest) { console.log(`Frame time: ${latest.frameTimeMs}ms`);}
// Get all recorded framesconst frames = history.getAll();Editor Integration
The profiler panel is accessible from the editor toolbar. It provides:
- Pause/resume stats collection
- Per-frame inspection — step through individual frames to analyze spikes
- System timing breakdown per frame