chore: Add SELECT benchmark coverage for read-path overhead (#45)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Marcelo Soares <marcelo.me.soares@gmail.com>
This commit is contained in:
parent
539f27b5d2
commit
83fbef8d2c
2 changed files with 22 additions and 8 deletions
|
|
@ -11,7 +11,7 @@ import 'package:serverpod_offline_sync_test_client/serverpod_offline_sync_test_c
|
||||||
|
|
||||||
import 'tables.dart';
|
import 'tables.dart';
|
||||||
|
|
||||||
enum Operation { insert, update, delete }
|
enum Operation { select, insert, update, delete }
|
||||||
|
|
||||||
enum StorageStage { insert, update, delete }
|
enum StorageStage { insert, update, delete }
|
||||||
|
|
||||||
|
|
@ -175,6 +175,14 @@ class TypesTableBenchmark extends AsyncBenchmarkBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<Types>> _selectTypes() async {
|
||||||
|
final rows = await Types.db.find(crdtEnabled ? _crdtSession! : _plainSession);
|
||||||
|
if (rows.length != rowCount) {
|
||||||
|
throw Exception('Rows count is ${rows.length} but expected $rowCount.');
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _bootstrapDatabase() async {
|
Future<void> _bootstrapDatabase() async {
|
||||||
await clearUserTables(_plainSession);
|
await clearUserTables(_plainSession);
|
||||||
CrdtUserManager.clearCache();
|
CrdtUserManager.clearCache();
|
||||||
|
|
@ -214,6 +222,9 @@ class TypesTableBenchmark extends AsyncBenchmarkBase {
|
||||||
_seededRows = [];
|
_seededRows = [];
|
||||||
}
|
}
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
|
case Operation.select:
|
||||||
|
_seededRows = await _insertTypes(rowCount);
|
||||||
|
return;
|
||||||
case Operation.insert:
|
case Operation.insert:
|
||||||
return;
|
return;
|
||||||
case Operation.update:
|
case Operation.update:
|
||||||
|
|
@ -301,6 +312,9 @@ class TypesTableBenchmark extends AsyncBenchmarkBase {
|
||||||
@override
|
@override
|
||||||
Future<void> run() async {
|
Future<void> run() async {
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
|
case Operation.select:
|
||||||
|
_lastRowsCount = (await _selectTypes()).length;
|
||||||
|
return;
|
||||||
case Operation.insert:
|
case Operation.insert:
|
||||||
_seededRows = await _insertTypes(rowCount);
|
_seededRows = await _insertTypes(rowCount);
|
||||||
_lastRowsCount = _seededRows.length;
|
_lastRowsCount = _seededRows.length;
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,16 @@ import 'benchmark.dart';
|
||||||
import 'conversion.dart';
|
import 'conversion.dart';
|
||||||
|
|
||||||
void printPerformanceImpact(
|
void printPerformanceImpact(
|
||||||
BenchmarkResults benchmarkResults, {
|
BenchmarkResults results, {
|
||||||
required int rowCount,
|
required int rowCount,
|
||||||
bool runningInCI = false,
|
bool runningInCI = false,
|
||||||
}) {
|
}) {
|
||||||
print(
|
print(
|
||||||
'${runningInCI ? '```' : ''}'
|
'${runningInCI ? '```' : ''}'
|
||||||
'\n📊 ${benchmarkResults.operation.name.toUpperCase()} performance impact:',
|
'\n📊 ${results.operation.name.toUpperCase()} performance impact:',
|
||||||
);
|
);
|
||||||
final baselineTime = benchmarkResults.baseline;
|
final baselineTime = results.baseline;
|
||||||
final crdtTime = benchmarkResults.crdt;
|
final crdtTime = results.crdt;
|
||||||
|
|
||||||
final runDelayUs = crdtTime - baselineTime;
|
final runDelayUs = crdtTime - baselineTime;
|
||||||
final slowdown = runDelayUs / baselineTime * 100;
|
final slowdown = runDelayUs / baselineTime * 100;
|
||||||
|
|
@ -25,9 +25,9 @@ void printPerformanceImpact(
|
||||||
|
|
||||||
print(' Time: $baselineDelay --> $crdtDelay ($runDelay)');
|
print(' Time: $baselineDelay --> $crdtDelay ($runDelay)');
|
||||||
print(' CRDT overhead: ${formatter2.format(slowdown)}% slower');
|
print(' CRDT overhead: ${formatter2.format(slowdown)}% slower');
|
||||||
print(
|
if (results.operation != Operation.select) {
|
||||||
' Delay per ${benchmarkResults.operation.name}: $runDelayPerOperation',
|
print(' Delay per ${results.operation.name}: $runDelayPerOperation');
|
||||||
);
|
}
|
||||||
if (runningInCI) print('```');
|
if (runningInCI) print('```');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue