Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ferry_sqlite_store): initial implementation #627

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions benchmark/ferry_store_benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
3 changes: 3 additions & 0 deletions benchmark/ferry_store_benchmark/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
39 changes: 39 additions & 0 deletions benchmark/ferry_store_benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.

For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).

For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
8 changes: 8 additions & 0 deletions benchmark/ferry_store_benchmark/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

include: package:lints/recommended.yaml

analyzer:
language:
strict-raw-types: true
strict-casts: true
strict-inference: true
184 changes: 184 additions & 0 deletions benchmark/ferry_store_benchmark/bin/benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import 'package:benchmark_harness/perf_benchmark_harness.dart';
import 'package:ferry_hive_ce_store/ferry_hive_ce_store.dart';
import 'package:ferry_sqlite_store/ferry_sqlite_store.dart';
import 'package:hive_ce/hive.dart';
import 'package:sqlite3/sqlite3.dart';

class HiveBenchmark extends PerfBenchmarkBase {
final HiveStore store;

HiveBenchmark(Box<dynamic> box)
: store = HiveStore(box),
super('Hive');

@override
Future<void> setup() async {
prepareData(store);
}

@override
Future<void> run() async {
benchmarkStoreGet(store);
}
}

class Sqlite3Benchmark extends PerfBenchmarkBase {
final Sqlite3StoreInMemoryFlush store;

Sqlite3Benchmark(Database db)
: store = Sqlite3StoreInMemoryFlush(db),
super('Sqlite3');

@override
void setup() {
prepareData(store);
}

@override
Future<void> run() async {
benchmarkStoreGet(store);
}
}

class Sqlite3StoreWriteThrough extends PerfBenchmarkBase {
final Sqlite3StoreInMemoryWriteThrough store;

Sqlite3StoreWriteThrough(Database db)
: store = Sqlite3StoreInMemoryWriteThrough(db),
super('Sqlite3 Write Through');

@override
void setup() {
prepareData(store);
}

@override
Future<void> run() async {
benchmarkStoreGet(store);
}
}

class Sqlite3StoreWriteThroughPut extends PerfBenchmarkBase {
final Sqlite3StoreInMemoryWriteThrough store;

Sqlite3StoreWriteThroughPut(Database db)
: store = Sqlite3StoreInMemoryWriteThrough(db),
super('Sqlite3 Write Through Put');

@override
void setup() {
prepareData(store);
}

@override
Future<void> run() async {
benchMarkStorePut(store);
}
}

class HiveStorePut extends PerfBenchmarkBase {
final HiveStore store;

HiveStorePut(Box<dynamic> box)
: store = HiveStore(box),
super('Hive Put');

@override
Future<void> setup() async {
prepareData(store);
}

@override
Future<void> run() async {
benchMarkStorePut(store);
}
}

class Sqlite3StorePut extends PerfBenchmarkBase {
final Sqlite3StoreInMemoryFlush store;

Sqlite3StorePut(Database db)
: store = Sqlite3StoreInMemoryFlush(db),
super('Sqlite3 Put');

@override
void setup() {
prepareData(store);
}

@override
Future<void> run() async {
benchMarkStorePut(store);
}
}

void main() async {
Hive.init('./test/__hive_data__');
final hiveBox = await Hive.openBox<dynamic>('graphql');
//WAL
final sqlite3Db =
sqlite3.open('/tmp/ferry_sqlite3.db', mode: OpenMode.readWriteCreate);

final hiveBenchmark = HiveBenchmark(hiveBox);
final sqlite3Benchmark = Sqlite3Benchmark(sqlite3Db);

final sqlite3Db2 =
sqlite3.open('/tmp/ferry_sqlite3_2.db', mode: OpenMode.readWriteCreate);

final sqlite3StoreWriteThrough = Sqlite3StoreWriteThrough(sqlite3Db2);

hiveBenchmark.report();
sqlite3Benchmark.report();
sqlite3StoreWriteThrough.report();

final sqlite3Db3 =
sqlite3.open('/tmp/ferry_sqlite3_3.db', mode: OpenMode.readWriteCreate);

final sqlite3StoreWriteThroughPut = Sqlite3StoreWriteThroughPut(sqlite3Db3);

sqlite3StoreWriteThroughPut.report();

final hiveBox2 = await Hive.openBox<dynamic>('graphql2');

final hiveStorePut = HiveStorePut(hiveBox2);

hiveStorePut.report();

final sqlite3Db4 =
sqlite3.open('/tmp/ferry_sqlite3_4.db', mode: OpenMode.readWriteCreate);

final sqlite3StorePut = Sqlite3StorePut(sqlite3Db4);

sqlite3StorePut.report();
}

void prepareData(Store store) {
final data = {
'Query': {
'posts': [
{'\$ref': 'Post:123'}
]
},
'Post:123': {
'id': '123',
'__typename': 'Post',
},
};

store.putAll(data);
}

void benchmarkStoreGet(Store store) {
for (var key in ['Query', 'Post:123']) {
store.get(key);
}
}

void benchMarkStorePut(Store store) {
for (int i = 0; i < 1000; i++) {
store.put('Post:$i', {
'id': '$i',
'__typename': 'Post',
});
}
}
Loading
Loading