Skip to content

Conversation

@faogustavo
Copy link
Collaborator

@faogustavo faogustavo commented Nov 11, 2025

  • Added a simple way to track the app frame rate to help identify any possible bottlenecks
image

No release notes as it's just in the sample app


Note

Adds a composable FPS counter with selectable counting modes, toggleable from Welcome view, and displayed in the title bar.

  • Samples UI:
    • New Component: components/FpsCounter.kt measures FPS (real-time, fixed interval, fixed frame count), tracks min/max, and color-codes output.
    • Title Bar: Conditionally displays FpsCounter in TitleBarView when MainViewModel.showFPSCount is true.
    • Welcome View: Adds "Show FPS Count" checkbox to toggle visibility.
    • ViewModel: Introduces showFPSCount state in MainViewModel.

Written by Cursor Bugbot for commit caed965. This will update automatically on new commits. Configure here.

- Added a simple way to track the app frame rate to help identify any possible bottlenecks
withFrameMillis { frameTimeMillis ->
fpsCount.getAndUpdate { it + 1 }

fpsArray[writeIndex.get()] = 1000f / (frameTimeMillis - lastUpdTime.getAndSet(frameTimeMillis))
Copy link

Choose a reason for hiding this comment

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

Bug: Time Collisions Cause FPS Instability

Division by zero: if two consecutive frames occur at the exact same millisecond timestamp, frameTimeMillis - lastUpdTime.getAndSet(frameTimeMillis) equals zero, causing division by zero and storing Infinity in fpsArray. This leads to incorrect FPS calculations and potentially NaN values when averaging.

Fix in Cursor Fix in Web

Copy link
Collaborator

@rock3r rock3r left a comment

Choose a reason for hiding this comment

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

I would just... not add an FPS counter. The meaning of the value it shows is misleading at best, and I am worried people might get complacent that slow code is still not impacting the framerate of redraws (which is capped to the screen's framerate...), while not seeing that there might be several recompositions and wasted work for each of those frames.

@faogustavo
Copy link
Collaborator Author

Makes sense, I'll just close this PR. I just opened as it was part of the base branch for lazy table and it could be useful in some situations.

@faogustavo faogustavo closed this Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants