From e1d7079d7814484bf497a7d0f5b941de59976f8c Mon Sep 17 00:00:00 2001 From: David Morgan Date: Fri, 20 Dec 2024 10:41:32 +0100 Subject: [PATCH] WIP, not for submit: benchmark analyzer-based generation / incremental generation by number of files. --- _test/bin/benchmark.dart | 57 ++++++++++++++++++++++++++++++ _test/lib/built_value1.dart | 10 ++++++ _test/lib/built_value1.g.dart | 65 +++++++++++++++++++++++++++++++++++ _test/pubspec.yaml | 2 ++ _test/test/common/utils.dart | 16 ++++++--- 5 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 _test/bin/benchmark.dart create mode 100644 _test/lib/built_value1.dart create mode 100644 _test/lib/built_value1.g.dart diff --git a/_test/bin/benchmark.dart b/_test/bin/benchmark.dart new file mode 100644 index 000000000..69cefd70f --- /dev/null +++ b/_test/bin/benchmark.dart @@ -0,0 +1,57 @@ +import 'dart:io'; + +import '../test/common/utils.dart'; + +Future main() async { + // only works in test + inTest = false; + ensureCleanGitClient(); + print('Initial build.'); + await runBuild(); + print('Done.'); + + print('Files,Build time/ms'); + for (final size in [ + 100, + 500, + 1000, + 1500, + 2000, + 2500, + 3000, + 3500, + 4000, + 4500, + 5000, + ]) { + stdout.write('$size,'); + + for (var i = 0; i != size; ++i) { + await createFile('lib/built_value${i + 1}.dart', ''' +import 'package:built_value/built_value.dart'; + +part 'built_value${i + 1}.g.dart'; + +abstract class Value implements Built { + Value._(); + factory Value([void Function(ValueBuilder)? updates]) = _\$Value; +} +'''); + } + await runBuild(); + await createFile('lib/built_value1.dart', ''' +import 'package:built_value/built_value.dart'; + +part 'built_value1.g.dart'; + +abstract class Value implements Built { + int get x; + Value._(); + factory Value([void Function(ValueBuilder)? updates]) = _\$Value; +} +'''); + final stopwatch = Stopwatch()..start(); + await runBuild(); + print(stopwatch.elapsedMilliseconds); + } +} diff --git a/_test/lib/built_value1.dart b/_test/lib/built_value1.dart new file mode 100644 index 000000000..06ea0c106 --- /dev/null +++ b/_test/lib/built_value1.dart @@ -0,0 +1,10 @@ +import 'package:built_value/built_value.dart'; + + + +part 'built_value1.g.dart'; + +abstract class Value implements Built { + Value._(); + factory Value([void Function(ValueBuilder)? updates]) = _$Value; +} diff --git a/_test/lib/built_value1.g.dart b/_test/lib/built_value1.g.dart new file mode 100644 index 000000000..7effc11a0 --- /dev/null +++ b/_test/lib/built_value1.g.dart @@ -0,0 +1,65 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'built_value1.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +class _$Value extends Value { + factory _$Value([void Function(ValueBuilder)? updates]) => + (new ValueBuilder()..update(updates))._build(); + + _$Value._() : super._(); + + @override + Value rebuild(void Function(ValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + ValueBuilder toBuilder() => new ValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Value; + } + + @override + int get hashCode { + return 887435281; + } + + @override + String toString() { + return newBuiltValueToStringHelper(r'Value').toString(); + } +} + +class ValueBuilder implements Builder { + _$Value? _$v; + + ValueBuilder(); + + @override + void replace(Value other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$Value; + } + + @override + void update(void Function(ValueBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + Value build() => _build(); + + _$Value _build() { + final _$result = _$v ?? new _$Value._(); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: deprecated_member_use_from_same_package,type=lint diff --git a/_test/pubspec.yaml b/_test/pubspec.yaml index 74954b46a..b8e412d80 100644 --- a/_test/pubspec.yaml +++ b/_test/pubspec.yaml @@ -6,6 +6,7 @@ environment: sdk: ^3.6.0 dependencies: + built_value: ^8.9.0 web: ^1.0.0 dev_dependencies: @@ -18,6 +19,7 @@ dev_dependencies: build_runner_core: any build_test: any build_web_compilers: any + built_value_generator: ^8.9.0 dart_flutter_team_lints: ^3.1.0 io: ^1.0.0 path: ^1.8.0 diff --git a/_test/test/common/utils.dart b/_test/test/common/utils.dart index c966b005d..cd0f96408 100644 --- a/_test/test/common/utils.dart +++ b/_test/test/common/utils.dart @@ -11,6 +11,8 @@ import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:test_process/test_process.dart'; +bool inTest = true; + Directory _generatedDir = Directory(p.join(_toolDir.path, 'generated')); Directory _toolDir = Directory(p.join('.dart_tool', 'build')); @@ -55,8 +57,8 @@ Future _runBuild(String command, List args, } final result = await Process.run(command, args); - printOnFailure('${result.stdout}'); - printOnFailure('${result.stderr}'); + if (inTest) printOnFailure('${result.stdout}'); + if (inTest) printOnFailure('${result.stderr}'); return result; } @@ -123,10 +125,14 @@ bool _gitIsClean() { /// state for this directory after running the test. void ensureCleanGitClient() { var gitWasClean = _gitIsClean(); - expect(gitWasClean, isTrue, + if (inTest) {expect(gitWasClean, isTrue, reason: 'Not running on a clean git client, aborting test.\n'); + } else { + if (!gitWasClean) throw 'Not running on a clean git client, aborting.'; + } + - addTearDown(_resetGitClient); + if (inTest) addTearDown(_resetGitClient); } Future _resetGitClient() async { @@ -216,7 +222,7 @@ Future expectTestsPass( Future createFile(String path, String contents) async { var file = File(path); - expect(await file.exists(), isFalse); + if (inTest) expect(await file.exists(), isFalse); await file.create(recursive: true); await file.writeAsString(contents); }