"Average FPS" is calculated wrongly - for example, a 30FPS case is reported ~45FPS
- Langage dominant
- Dart
- Étoiles
- 1.7k
- Forks
- 404
- Merge moyen
- 6 j 17 h
- PR mergées (30 j)
- 18
Description
## Suspected cause
The FPS should be calculated as "how many frames (i.e. new pictures) are shown on the screen per second", instead of "how long does the ui thread take to compute one frame", because the latter forgets the idle time in the ui thread also counts.
## Description
Run the code (better in profile mode)
```dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
State createState() => _MyAppState();
}
class _MyAppState extends State {
var count = 0;
@override
Widget build(BuildContext context) {
sleep(const Duration(milliseconds: 17));
count++;
SchedulerBinding.instance.addPostFrameCallback((_) => setState(() {}));
return MaterialApp(home: Scaffold(body: Center(child: Text('$count'))));
}
}
```
Open devtool and see: (notice it says "45fps")

zoom in and see: (left of "1" is 1244325196370 μs, left of "2" is 1244325497120 μs)

By simple math, (1244325497120-1244325196370)/9 = 33.416ms, we know between each rasterization there are nearly 33.416 ms. This is exactly 33.333ms which is 30FPS!
Thus, in this simple example, it should say 30FPS but wrongly report 45FPS.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Reproduce the example in Flutter DevTools, preferably in profile mode, and inspect the FPS calculation alongside the rasterization timestamps. Compare the displayed average with the interval between rasterizations; done means the example reports approximately 30 FPS rather than 45 FPS.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- dart, devtools
- Domaine
- observability, performance
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100