diff --git a/benchmark/README.md b/benchmark/README.md index 28d8bb5..35c6abd 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -159,7 +159,7 @@ of SVG optimization in real-world application scenarios. Key Points: -- The benchmarking was performed on an example application that utilizes the `svg_optimizer`package. +- The benchmarking was performed on an example application that utilizes the `svg_optimizer` package. - A comprehensive test covering all SVG files included in the project was conducted. - The results indicated a notable improvement, with a ~30% reduction in the time required to render SVGs on-screen. - The testing device used for this benchmark was an iPhone 15 Plus. \ No newline at end of file diff --git a/benchmark/lib/benchmark.dart b/benchmark/lib/benchmark.dart index 1a89b7b..6525b9c 100644 --- a/benchmark/lib/benchmark.dart +++ b/benchmark/lib/benchmark.dart @@ -25,19 +25,22 @@ class Benchmark { // Reset pubspec.yaml to original form before making changes yamlFile.writeAsStringSync(originalYaml.toString()); - final List currentAssets = jsonDecode(jsonEncode(editor.parseAt(['flutter', 'assets']).value)); + final List currentAssets = + jsonDecode(jsonEncode(editor.parseAt(['flutter', 'assets']).value)); late final int nonOptimizedBuildSize; late final int optimizedBuildSize; // Append assets to pubspec.yaml without transformer - projectSize.getAssetRecords(false).forEach((element) => editor.appendToList(['flutter', 'assets'], element)); + projectSize.getAssetRecords(false).forEach( + (element) => editor.appendToList(['flutter', 'assets'], element)); yamlFile.writeAsStringSync(editor.toString()); // Make a benchmark with non optimized SVG files Directory.current = Directory('../example'); print('Building without svg_optimizer...'); - final ProcessResult nonOptimizedResult = await Process.run('flutter', platform.buildArguments); + final ProcessResult nonOptimizedResult = + await Process.run('flutter', platform.buildArguments); if (nonOptimizedResult.exitCode != 0) { print(nonOptimizedResult.stderr); throw Exception('Failed to build non optimized project'); @@ -49,13 +52,15 @@ class Benchmark { // Reset previous changes to assets in pubspec.yaml editor.update(['flutter', 'assets'], currentAssets); // Append assets to pubspec.yaml with transformer - projectSize.getAssetRecords(true).forEach((element) => editor.appendToList(['flutter', 'assets'], element)); + projectSize.getAssetRecords(true).forEach( + (element) => editor.appendToList(['flutter', 'assets'], element)); yamlFile.writeAsStringSync(editor.toString()); // Make a benchmark with optimized SVG files print('Building with svg_optimizer...'); Directory.current = Directory('../example'); - final ProcessResult optimizedResult = await Process.run('flutter', platform.buildArguments); + final ProcessResult optimizedResult = + await Process.run('flutter', platform.buildArguments); if (optimizedResult.exitCode != 0) { print(optimizedResult.stderr); throw Exception('Failed to build optimized project'); diff --git a/benchmark/lib/benchmark_result.dart b/benchmark/lib/benchmark_result.dart index cef469a..39d2624 100644 --- a/benchmark/lib/benchmark_result.dart +++ b/benchmark/lib/benchmark_result.dart @@ -10,7 +10,8 @@ class BenchmarkResult { }); @override - String toString() => 'Build size without svg_optimizer: ${FileSizeFormatter.format(nonOptimizedBuildSize)}\n' + String toString() => + 'Build size without svg_optimizer: ${FileSizeFormatter.format(nonOptimizedBuildSize)}\n' 'Build size with svg_optimizer: ${FileSizeFormatter.format(optimizedBuildSize)}\n' 'Optimized build size is ${FileSizeFormatter.format(nonOptimizedBuildSize - optimizedBuildSize)} smaller ' '(${((nonOptimizedBuildSize - optimizedBuildSize) / nonOptimizedBuildSize * 100).toStringAsFixed(2)}%)\n'; diff --git a/benchmark/lib/project_size.dart b/benchmark/lib/project_size.dart index 534ef01..4e54841 100644 --- a/benchmark/lib/project_size.dart +++ b/benchmark/lib/project_size.dart @@ -11,17 +11,20 @@ enum ProjectSize { } extension ProjectSizeExtension on ProjectSize { - List> getAssetRecords(bool withTransformer) => switch (this) { + List> getAssetRecords(bool withTransformer) => + switch (this) { ProjectSize.small => [ AssetRecordUtils.getAssetRecord(_smallProjectPath, withTransformer), ], ProjectSize.medium => [ AssetRecordUtils.getAssetRecord(_smallProjectPath, withTransformer), - AssetRecordUtils.getAssetRecord(_mediumProjectPath, withTransformer), + AssetRecordUtils.getAssetRecord( + _mediumProjectPath, withTransformer), ], ProjectSize.big => [ AssetRecordUtils.getAssetRecord(_smallProjectPath, withTransformer), - AssetRecordUtils.getAssetRecord(_mediumProjectPath, withTransformer), + AssetRecordUtils.getAssetRecord( + _mediumProjectPath, withTransformer), AssetRecordUtils.getAssetRecord(_bigProjectPath, withTransformer), ], }; diff --git a/benchmark/svg_optimizer_benchmark.dart b/benchmark/svg_optimizer_benchmark.dart index 011670a..c334229 100644 --- a/benchmark/svg_optimizer_benchmark.dart +++ b/benchmark/svg_optimizer_benchmark.dart @@ -14,7 +14,8 @@ Future main(List arguments) async { final ArgParser argParser = buildParser(); final ArgResults results = argParser.parse(arguments); - SupportedPlatform? platform = SupportedPlatform.values.firstWhereOrNull((element) => results[element.value] == true); + SupportedPlatform? platform = SupportedPlatform.values + .firstWhereOrNull((element) => results[element.value] == true); if (platform == null) { print('Please provide platform argument'); diff --git a/benchmark/utils/asset_record_utils.dart b/benchmark/utils/asset_record_utils.dart index 89b035b..2faf556 100644 --- a/benchmark/utils/asset_record_utils.dart +++ b/benchmark/utils/asset_record_utils.dart @@ -1,5 +1,7 @@ abstract class AssetRecordUtils { - static Map getAssetRecord(String path, bool withTransformer) => { + static Map getAssetRecord( + String path, bool withTransformer) => + { 'path': path, if (withTransformer) 'transformers': [ diff --git a/example/lib/benchmarks/loading_svg_benchmark_app.dart b/example/lib/benchmarks/loading_svg_benchmark_app.dart index 14e8966..47c3aed 100644 --- a/example/lib/benchmarks/loading_svg_benchmark_app.dart +++ b/example/lib/benchmarks/loading_svg_benchmark_app.dart @@ -54,16 +54,20 @@ class _BenchmarkPageState extends State { } Future> getSvgPaths() async { - final List bigProjectImages = await getImagePaths('assets/benchmark_svg/big_project'); - final List mediumProjectImages = await getImagePaths('assets/benchmark_svg/medium_project'); - final List smallProjectImages = await getImagePaths('assets/benchmark_svg/small_project'); + final List bigProjectImages = + await getImagePaths('assets/benchmark_svg/big_project'); + final List mediumProjectImages = + await getImagePaths('assets/benchmark_svg/medium_project'); + final List smallProjectImages = + await getImagePaths('assets/benchmark_svg/small_project'); return bigProjectImages + mediumProjectImages + smallProjectImages; } - Future> getImagePaths(String path) async => jsonDecode(await rootBundle.loadString('AssetManifest.json')) - .keys - .where((String key) => key.contains(path)) - .toList(); + Future> getImagePaths(String path) async => + jsonDecode(await rootBundle.loadString('AssetManifest.json')) + .keys + .where((String key) => key.contains(path)) + .toList(); } const Key picturesListKey = ValueKey('picturesListKey'); diff --git a/example/lib/main.dart b/example/lib/main.dart index 429284f..9457ce2 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -45,7 +45,8 @@ class _MyHomePageState extends State { children: [ const Text('Non optimized svg:'), FutureBuilder( - future: rootBundle.loadString('assets/svg_no_optimize/heart.svg'), + future: + rootBundle.loadString('assets/svg_no_optimize/heart.svg'), builder: (context, snapshot) { if (snapshot.hasData) { return Text(snapshot.data!); diff --git a/lib/optimize/optimizer.dart b/lib/optimize/optimizer.dart index 70b096d..4c0c157 100644 --- a/lib/optimize/optimizer.dart +++ b/lib/optimize/optimizer.dart @@ -45,7 +45,8 @@ void optimizeSvg(List arguments) { print(argParser.usage); exit(1); } on ProcessException catch (_) { - print('It looks like svgo is not configured properly. To install it, refer to README file.'); + print( + 'It looks like svgo is not configured properly. To install it, refer to README file.'); exit(1); } catch (e) { print(e.toString());