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

A pile of cleanup commits #531

Merged
merged 14 commits into from
Jul 27, 2021
Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
.packages
.pub
build/
generated/
**/lib/generated/**
packages
pubspec.lock
82 changes: 79 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
analyzer:
exclude:
- benchmarks/query_benchmark/**
linter:
rules:
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_empty_else
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_relative_lib_imports
- avoid_renaming_method_parameters
- avoid_return_types_on_setters
- avoid_returning_null_for_void
- avoid_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
- avoid_types_as_parameter_names
- await_only_futures
- camel_case_extensions
- camel_case_types
- constant_identifier_names
- control_flow_in_finally
- curly_braces_in_flow_control_structures
- directives_ordering
- empty_catches
- empty_constructor_bodies
- empty_statements
- exhaustive_cases
- file_names
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- library_names
- library_prefixes
- list_remove_unrelated_type
- no_duplicate_case_values
- non_constant_identifier_names
- null_closures
- overridden_fields
- package_names
- package_prefixed_library_names
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
- prefer_for_elements_to_map_fromIterable
- prefer_function_declarations_over_variables
- prefer_generic_function_type_aliases
- prefer_if_null_operators
- prefer_initializing_formals
- prefer_inlined_adds
- prefer_is_empty
- prefer_is_not_empty
- prefer_is_not_operator
- prefer_iterable_whereType
- prefer_null_aware_operators
- prefer_relative_imports
- prefer_single_quotes
- prefer_spread_collections
- prefer_typing_uninitialized_variables
- prefer_void_to_null
- provide_deprecation_message
- recursive_getters
- slash_for_doc_comments
- type_init_formals
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_getters_setters
- unnecessary_new
- unnecessary_null_in_if_null_operators
- unnecessary_overrides
- unnecessary_string_escapes
- unnecessary_string_interpolations
- unnecessary_this
- unrelated_type_equality_checks
- use_function_type_syntax_for_parameters
- use_rethrow_when_possible
- valid_regexps
- void_checks
20 changes: 9 additions & 11 deletions api_benchmark/lib/benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library protoc.benchmark;

import 'generated/benchmark.pb.dart' as pb;

typedef Benchmark CreateBenchmarkFunc(pb.Request request);
typedef CreateBenchmarkFunc = Benchmark Function(pb.Request request);

// Describes how to construct a benchmark.
class BenchmarkType {
Expand All @@ -23,7 +21,7 @@ abstract class Profiler {
/// A benchmark that also reports the counts for various operations.
/// (A modification of BenchmarkBase from the benchmark_harness library.)
abstract class Benchmark {
static const int _DEFAULT_REPS = 10;
static const int _defaultReps = 10;

final pb.BenchmarkID id;
Benchmark(this.id);
Expand Down Expand Up @@ -72,7 +70,7 @@ abstract class Benchmark {

void checkRequest(pb.Request r) {
if (r.id != id) {
throw ArgumentError("invalid benchmark id: ${r.id}");
throw ArgumentError('invalid benchmark id: ${r.id}');
}
if (r.params != makeParams()) {
throw ArgumentError("parameters don't match: ${r.params}");
Expand Down Expand Up @@ -104,10 +102,10 @@ abstract class Benchmark {

/// Exercises the code and returns the number of repetitions.
int exercise() {
for (int i = 0; i < _DEFAULT_REPS; i++) {
for (int i = 0; i < _defaultReps; i++) {
run();
}
return _DEFAULT_REPS;
return _defaultReps;
}

/// The code being measured.
Expand All @@ -128,14 +126,14 @@ abstract class Benchmark {
var median = measureSample(medianSample(r)).toStringAsFixed(0).padLeft(4);
var max = measureSample(maxSample(r)).toStringAsFixed(0).padLeft(4);

return "$prefix samples: $sampleCount"
" median: $median max: $max $measureSampleUnits";
return '$prefix samples: $sampleCount'
' median: $median max: $max $measureSampleUnits';
}

/// Returns the sample with the median measurement.
pb.Sample medianSample(pb.Response response) {
if (response == null || response.samples.isEmpty) return null;
var samples = []..addAll(response.samples);
var samples = [...response.samples];
samples.sort((a, b) {
return measureSample(a).compareTo(measureSample(b));
});
Expand All @@ -148,7 +146,7 @@ abstract class Benchmark {
if (response == null) return null;
pb.Sample best;
for (var s in response.samples) {
if (best == null) best = s;
best ??= s;
if (measureSample(best) < measureSample(s)) {
best = s;
}
Expand Down
18 changes: 8 additions & 10 deletions api_benchmark/lib/benchmarks/get_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library protoc.benchmark.get_strings;

import '../benchmark.dart';
import '../generated/benchmark.pb.dart'
show BenchmarkID, Request, Params, Sample;
Expand All @@ -20,8 +18,8 @@ class GetStringsBenchmark extends Benchmark {

@override
get summary {
var fill = fillValue == null ? "null" : "'$fillValue'";
return "${id.name}($height x $fill)";
var fill = fillValue == null ? 'null' : "'$fillValue'";
return '${id.name}($height x $fill)';
}

@override
Expand Down Expand Up @@ -90,7 +88,7 @@ class GetStringsBenchmark extends Benchmark {
ok = ok && line.cell9.isEmpty;
ok = ok && line.cell10.isEmpty;
}
if (!ok) throw "failed";
if (!ok) throw 'failed';
}

void _getStrings() {
Expand All @@ -107,26 +105,26 @@ class GetStringsBenchmark extends Benchmark {
ok = ok && line.cell9.isNotEmpty;
ok = ok && line.cell10.isNotEmpty;
}
if (!ok) throw "failed";
if (!ok) throw 'failed';
}

@override
void setCounts(Sample s) {
s.counts.stringReads = width * height * s.loopCount;
void setCounts(Sample m) {
m.counts.stringReads = width * height * m.loopCount;
}

@override
measureSample(Sample s) => stringReadsPerMillisecond(s);

@override
get measureSampleUnits => "string reads/ms";
get measureSampleUnits => 'string reads/ms';

static const $id = BenchmarkID.GET_STRINGS;
static final $type = BenchmarkType($id, $create);

static GetStringsBenchmark $create(Request r) {
assert(r.params.hasMessageCount());
var value = null;
String value;
if (r.params.hasStringValue()) value = r.params.stringValue;
return GetStringsBenchmark(r.params.messageCount, value);
}
Expand Down
18 changes: 8 additions & 10 deletions api_benchmark/lib/benchmarks/has_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library protoc.benchmark.has_strings;

import '../benchmark.dart';
import '../generated/benchmark.pb.dart'
show BenchmarkID, Request, Params, Sample;
Expand All @@ -20,8 +18,8 @@ class HasStringsBenchmark extends Benchmark {

@override
get summary {
var fill = fillValue == null ? "null" : "'$fillValue'";
return "${id.name}($height x $fill)";
var fill = fillValue == null ? 'null' : "'$fillValue'";
return '${id.name}($height x $fill)';
}

@override
Expand Down Expand Up @@ -90,7 +88,7 @@ class HasStringsBenchmark extends Benchmark {
allPresent = allPresent && line.hasCell9();
allPresent = allPresent && line.hasCell10();
}
if (!allPresent) throw "failed";
if (!allPresent) throw 'failed';
}

void runEmpty() {
Expand All @@ -107,26 +105,26 @@ class HasStringsBenchmark extends Benchmark {
allEmpty = allEmpty && !line.hasCell9();
allEmpty = allEmpty && !line.hasCell10();
}
if (!allEmpty) throw "failed";
if (!allEmpty) throw 'failed';
}

@override
void setCounts(Sample s) {
s.counts.stringReads = width * height * s.loopCount;
void setCounts(Sample m) {
m.counts.stringReads = width * height * m.loopCount;
}

@override
measureSample(Sample s) => stringReadsPerMillisecond(s);

@override
get measureSampleUnits => "string reads/ms";
get measureSampleUnits => 'string reads/ms';

static const $id = BenchmarkID.HAS_STRINGS;
static final $type = BenchmarkType($id, $create);

static HasStringsBenchmark $create(Request r) {
assert(r.params.hasMessageCount());
var value = null;
String value;
if (r.params.hasStringValue()) value = r.params.stringValue;
return HasStringsBenchmark(r.params.messageCount, value);
}
Expand Down
30 changes: 12 additions & 18 deletions api_benchmark/lib/benchmarks/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library protoc.benchmark.index;

import "../benchmark.dart";

import "int32_json.dart";
import "int64_json.dart";
import "string_json.dart";

import "repeated_int32_json.dart";
import "repeated_int64_json.dart";
import "repeated_string_json.dart";

import "get_strings.dart";
import "set_strings.dart";
import "has_strings.dart";

import '../benchmark.dart';
import '../generated/benchmark.pb.dart' as pb;
import 'get_strings.dart';
import 'has_strings.dart';
import 'int32_json.dart';
import 'int64_json.dart';
import 'repeated_int32_json.dart';
import 'repeated_int64_json.dart';
import 'repeated_string_json.dart';
import 'set_strings.dart';
import 'string_json.dart';

/// Creates the appropriate Benchmark instance for a protobuf.
Benchmark createBenchmark(pb.Request r) {
var type = allBenchmarks[r.id];
if (type == null) {
throw ArgumentError("unknown benchmark: ${r.id.name}");
throw ArgumentError('unknown benchmark: ${r.id.name}');
}
return type.create(r);
}
Expand All @@ -45,7 +39,7 @@ Map<pb.BenchmarkID, BenchmarkType> _makeTypeMap(List<BenchmarkType> types) {
var out = <pb.BenchmarkID, BenchmarkType>{};
for (var type in types) {
if (out.containsKey(type.id)) {
throw "already added: $type.id.name";
throw 'already added: $type.id.name';
}
out[type.id] = type;
}
Expand Down
14 changes: 6 additions & 8 deletions api_benchmark/lib/benchmarks/int32_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library protoc.benchmark.int32_json;

import '../benchmark.dart';
import '../generated/benchmark.pb.dart'
show BenchmarkID, Request, Params, Sample;
Expand All @@ -19,7 +17,7 @@ class Int32Benchmark extends Benchmark {
Int32Benchmark(this.width, this.height) : super($id);

@override
get summary => "${id.name}($width x $height int32s)";
get summary => '${id.name}($width x $height int32s)';

@override
Params makeParams() => Params()
Expand All @@ -38,7 +36,7 @@ class Int32Benchmark extends Benchmark {
// 1 2 3 4
// 2 3 4 5
static pb.Grid10 _makeGrid(int width, int height) {
if (width > 10) throw ArgumentError("width out of range: ${width}");
if (width > 10) throw ArgumentError('width out of range: $width');
var grid = pb.Grid10();

for (int y = 0; y < height; y++) {
Expand All @@ -61,19 +59,19 @@ class Int32Benchmark extends Benchmark {
void run() {
pb.Grid10 grid = pb.Grid10.fromJson(json);
var actual = grid.lines[height - 1].getField(lastFieldTag);
if (actual != width + height - 2) throw "failed; got ${actual}";
if (actual != width + height - 2) throw 'failed; got $actual';
}

@override
void setCounts(Sample s) {
s.counts.int32Reads = width * height * s.loopCount;
void setCounts(Sample m) {
m.counts.int32Reads = width * height * m.loopCount;
}

@override
measureSample(Sample s) => int32ReadsPerMillisecond(s);

@override
get measureSampleUnits => "int32 reads/ms";
get measureSampleUnits => 'int32 reads/ms';

static const $id = BenchmarkID.READ_INT32_FIELDS_JSON;
static final $type = BenchmarkType($id, $create);
Expand Down
Loading