perf(editor): native Windows preview and UI-first timeline navigation (#11)
Gitea CI / Check code and tests (push) Successful in 8m7s
Gitea CI / Build Windows x64 app (push) Successful in 5m48s
Gitea CI / Build Android APK (push) Successful in 5m59s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m17s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m22s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea CI / Check code and tests (push) Successful in 8m7s
Gitea CI / Build Windows x64 app (push) Successful in 5m48s
Gitea CI / Build Android APK (push) Successful in 5m59s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m17s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m22s
Gitea CI / Gitea CI passed (push) Successful in 2s
This commit was merged in pull request #11.
This commit is contained in:
1 parent
0ecf920669
commit
b4cb12cbe3
36 files changed
+3292
-148
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Native QPC clock calibration and bounded asynchronous diagnostics sampling.
|
||||
class BenchDiagnostics {
|
||||
BenchDiagnostics(this.sessionId, this.clock);
|
||||
final String sessionId;
|
||||
final Stopwatch clock;
|
||||
static const _channel = MethodChannel('cutdex_runtime');
|
||||
double uncertaintyMs = double.infinity, _offset = 0;
|
||||
Timer? _timer;
|
||||
Future<void>? _pending;
|
||||
Object? _sampleError;
|
||||
|
||||
double now() => _offset + clock.elapsedMicroseconds / 1000;
|
||||
Future<Map<String, dynamic>> read() async =>
|
||||
(await _channel.invokeMapMethod<String, dynamic>('previewDiagnostics', {
|
||||
'sessionId': sessionId,
|
||||
}))!;
|
||||
|
||||
Future<void> calibrate() async {
|
||||
for (var i = 0; i < 20; i++) {
|
||||
final begin = clock.elapsedMicroseconds / 1000;
|
||||
final diagnostic = await read();
|
||||
final end = clock.elapsedMicroseconds / 1000;
|
||||
if (end - begin < uncertaintyMs) {
|
||||
uncertaintyMs = end - begin;
|
||||
_offset = (diagnostic['qpcMs'] as num).toDouble() - (begin + end) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> until(double due) async {
|
||||
while (now() < due) {
|
||||
await Future<void>.delayed(
|
||||
Duration(microseconds: ((due - now()) * 1000).ceil().clamp(1, 1000000)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void startSamples(IOSink sink, int intervalMs) {
|
||||
_timer = Timer.periodic(Duration(milliseconds: intervalMs), (_) {
|
||||
if (_pending != null || _sampleError != null) return;
|
||||
_pending = _sample(sink).whenComplete(() => _pending = null);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _sample(IOSink sink) async {
|
||||
try {
|
||||
sink.writeln(jsonEncode(await read()));
|
||||
} catch (error) {
|
||||
_sampleError = error;
|
||||
}
|
||||
}
|
||||
|
||||
void check() {
|
||||
if (_sampleError != null) {
|
||||
throw StateError('Native sampler failed: $_sampleError');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> stopSamples() async {
|
||||
_timer?.cancel();
|
||||
await _pending;
|
||||
check();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user