flutter / flutter/devtools

"Average FPS" is calculated wrongly - for example, a 30FPS case is reported ~45FPS

Aperta
#4,522 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
needs discussion P2 screen: performance
Lingua principale
Dart
Stelle
1.7k
Fork
404
Merge medio
6g 17h
PR unite (30g)
18

Descrizione

## 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")

![image](https://user-images.githubusercontent.com/5236035/192140428-503adfbe-ecf2-4abe-8aad-5ac39c597414.png)

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

![image](https://user-images.githubusercontent.com/5236035/192140439-71d75135-6d57-40e6-a4af-96f1442f7d51.png)

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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
dart, devtools
Ambito
observability, performance
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.