Skip to content

Introducing Framecounter for measuring FPS#799

Draft
jfboeve wants to merge 4 commits into
mainfrom
feat/framecounter
Draft

Introducing Framecounter for measuring FPS#799
jfboeve wants to merge 4 commits into
mainfrom
feat/framecounter

Conversation

@jfboeve

@jfboeve jfboeve commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@jfboeve jfboeve marked this pull request as draft June 4, 2026 09:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new FPS “frame counter” utility and extends the fpsUpdate event payload to include bucketed frame-time counts, configurable via a new fpsBoundaries runtime setting.

Changes:

  • Introduces src/core/lib/fps.ts to track FPS and bucket frame delta times.
  • Wires Stage FPS tracking to the new frame counter and adds runtime update hooks for interval/boundaries.
  • Extends shared FpsUpdatePayload to include frameCount and plumbs fpsBoundaries through renderer settings.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
src/main-api/Renderer.ts Adds fpsBoundaries setting and propagates runtime updates to Stage.
src/core/Stage.ts Replaces legacy FPS aggregation with the new frame-counter-based approach and adds update methods.
src/core/lib/fps.ts New FPS/frame bucketing utility used by Stage.
src/common/CommonTypes.ts Extends FpsUpdatePayload with frameCount typing.

Comment thread src/core/Stage.ts
Comment on lines +208 to +212
// Set initial frame buckets and FPS update interval for FPS tracking
if (options.fpsBoundaries) {
setFrameBuckets(options.fpsBoundaries);
}
setFpsInterval(options.fpsUpdateInterval);
Comment thread src/core/Stage.ts
Comment on lines +558 to +560
let frameCounter = this.currentFrameCounter;
const eleapsed = this.elapsedTime;
if (frameCounter !== null && frameCounter.end < eleapsed) {
Comment thread src/core/Stage.ts
Comment on lines +557 to 561
if (fpsUpdateInterval > 0) {
let frameCounter = this.currentFrameCounter;
const eleapsed = this.elapsedTime;
if (frameCounter !== null && frameCounter.end < eleapsed) {
this.queueFrameEvent('fpsUpdate', {
Comment thread src/core/lib/fps.ts
Comment on lines +90 to +99
export function createFrameCounter(frameTime: number): FrameCounter {
const counter = Object.create(frameCounter) as FrameCounter;
counter.boundaries = boundaries;
counter.start = frameTime;
counter.end = frameTime + fpsInterval;
//fill frames with 0 for each bucket
for (let i = 0; i < boundaries.length; i++) {
const bucket = boundaries[i] as number;
counter.count[bucket] = 0;
}
Comment thread src/core/lib/fps.ts
Comment on lines +65 to +75
increment(frameDelta: number) {
this.total++;
for (let i = 0; i < boundaries.length; i++) {
const bucket = boundaries[i] as number;
if (frameDelta <= bucket) {
this.count[bucket]!++;
return;
}
}
this.count['overflow']!++;
},
Comment thread src/core/lib/fps.ts
Comment thread src/core/lib/fps.ts
Comment on lines +56 to +80
let boundaries = [20, 40, 60, 80, 100];
let fpsInterval = 1000; // 1 second

const frameCounter: FrameCounter = {
start: 0,
end: 0,
total: 0,
boundaries: [],
count: {},
increment(frameDelta: number) {
this.total++;
for (let i = 0; i < boundaries.length; i++) {
const bucket = boundaries[i] as number;
if (frameDelta <= bucket) {
this.count[bucket]!++;
return;
}
}
this.count['overflow']!++;
},
get averageFps() {
//calculate fps based on frame count and elapsed time
return (this.total / (this.end - this.start)) * 1000;
},
};
Comment thread src/common/CommonTypes.ts
Comment on lines 139 to 143
export interface FpsUpdatePayload {
fps: number;
contextSpyData: Record<string, number> | null;
frameCount: FrameCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants