Files
Paul Berry afcfbbeba8 Migrate developer experience packages to new constructor decl syntax.
(Part of https://github.com/dart-lang/sdk/issues/63288)

This change migrates the packages owned by the developer experience
team to use the new constructor declaration syntax, described in
https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations.

This change was performed in an automated fashion, by (a) bumping the
packages' SDK constraints to `3.13.0-0`, (b) enabling the lints
`unnecessary_type_name_in_constructor` and
`unnecessary_const_in_enum_constructor`, (c) fixing the resulting lint
failures using `dart fix`, and then (d) reformatting the affected
files.

To ease code review, I've reverted unrelated formatting changes.

Since this change requires bumping SDK constaints to `3.13.0-0`, it
was only performed on packages that are *not* published on
pub. (Packages that *are* published on pub should remain on lower
language versions until at least after the stable version of 3.13 is
released, so that we don't block users on the stable channel from
receiving updates to those packages.)

Change-Id: Ibb4daebafd239da58251e838ea6a3f336a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505046
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
2026-05-27 14:52:58 -07:00

227 lines
6.0 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// 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.
import 'dart:async';
import 'dart:io';
import 'package:path/path.dart' as path;
import '../benchmarks.dart';
import 'memory_tests.dart';
/// benchmarks:
/// - analysis-server-warm-analysis
/// - analysis-server-warm-memory
/// - analysis-server-edit
/// - analysis-server-completion
class AnalysisBenchmark extends Benchmark {
final AbstractBenchmarkTest Function() testConstructor;
new(ServerBenchmark benchmarkTest)
: testConstructor = benchmarkTest.testConstructor,
super(
benchmarkTest.id,
'${benchmarkTest.name} benchmarks of a large project, with an existing '
'driver cache.',
kind: 'group',
);
@override
Future<BenchMarkResult> run({
required String dartSdkPath,
bool quick = false,
bool verbose = false,
}) async {
var stopwatch = Stopwatch()..start();
var test = testConstructor();
if (verbose) {
test.debugStdio();
}
await test.setUp(dartSdkPath, getProjectRoots(quick: quick));
await test.analysisFinished;
stopwatch.stop();
var usedBytes = await test.getMemoryUsage();
var result = CompoundBenchMarkResult(id);
result.add(
'warm-analysis',
BenchMarkResult('micros', stopwatch.elapsedMicroseconds),
);
result.add('warm-memory', BenchMarkResult('bytes', usedBytes));
if (!quick) {
// change timing
var editMicros = await _calcEditTiming(test);
result.add('edit', BenchMarkResult('micros', editMicros));
// code completion
var completionMicros = await _calcCompletionTiming(test);
result.add('completion', BenchMarkResult('micros', completionMicros));
}
await test.shutdown();
return result;
}
Future<int> _calcCompletionTiming(AbstractBenchmarkTest test) async {
const kGroupCount = 10;
var filePath = path.join(
analysisServerSrcPath,
'lib',
'src',
'analysis_server.dart',
);
var contents = File(filePath).readAsStringSync();
await test.openFile(filePath, contents);
var completionCount = 0;
var stopwatch = Stopwatch()..start();
Future<void> complete(int offset) async {
await test.complete(filePath, offset, isWarmUp: false);
completionCount++;
}
for (var i = 0; i < kGroupCount; i++) {
var startIndex = i * (contents.length ~/ (kGroupCount + 2));
// Look for a line with a period in it that ends with a semi-colon.
var index = contents.indexOf(
RegExp(r'\..*;$', multiLine: true),
startIndex,
);
await complete(index - 10);
await complete(index - 1);
await complete(index);
await complete(index + 1);
await complete(index + 10);
if (i + 1 < kGroupCount) {
// mutate
index = contents.indexOf(';', index);
contents =
'${contents.substring(0, index + 1)} ${contents.substring(index + 1)}';
await test.updateFile(filePath, contents);
}
}
stopwatch.stop();
await test.closeFile(filePath);
return stopwatch.elapsedMicroseconds ~/ completionCount;
}
Future<int> _calcEditTiming(AbstractBenchmarkTest test) async {
const kGroupCount = 5;
var filePath = path.join(
analysisServerSrcPath,
'lib',
'src',
'analysis_server.dart',
);
var contents = File(filePath).readAsStringSync();
// Get the future for `analysisFinished` *before* the call to [openFile]
// as the analysis triggered by opening is sometimes so fast that it
// finishes before starting to listen if only starting *after* the call to
// [openFile].
Future<void> analysisFinished = test.analysisFinished;
await test.openFile(filePath, contents);
await analysisFinished;
var stopwatch = Stopwatch()..start();
for (var i = 0; i < kGroupCount; i++) {
var startIndex = i * (contents.length ~/ (kGroupCount + 2));
var index = contents.indexOf(';', startIndex);
contents =
'${contents.substring(0, index + 1)} ${contents.substring(index + 1)}';
await test.updateFile(filePath, contents);
await test.analysisFinished;
}
stopwatch.stop();
await test.closeFile(filePath);
return stopwatch.elapsedMicroseconds ~/ kGroupCount;
}
}
/// benchmarks:
/// - analysis-server-cold-analysis
/// - analysis-server-cold-memory
class ColdAnalysisBenchmark extends Benchmark {
final AbstractBenchmarkTest Function() testConstructor;
new(ServerBenchmark benchmarkTest)
: testConstructor = benchmarkTest.testConstructor,
super(
'${benchmarkTest.id}-cold',
'${benchmarkTest.name} benchmarks of a large project on start-up, no '
'existing driver cache.',
kind: 'group',
);
@override
int get maxIterations => 3;
@override
Future<BenchMarkResult> run({
required String dartSdkPath,
bool quick = false,
bool verbose = false,
}) async {
if (!quick) {
deleteServerCache();
}
var stopwatch = Stopwatch()..start();
var test = testConstructor();
await test.setUp(dartSdkPath, getProjectRoots(quick: quick));
await test.analysisFinished;
stopwatch.stop();
var usedBytes = await test.getMemoryUsage();
var result = CompoundBenchMarkResult(id);
result.add(
'analysis',
BenchMarkResult('micros', stopwatch.elapsedMicroseconds),
);
result.add('memory', BenchMarkResult('bytes', usedBytes));
await test.shutdown();
return result;
}
}
class ServerBenchmark {
static final das = ServerBenchmark(
'analysis-server',
'Analysis Server',
AnalysisServerBenchmarkTest.new,
);
static final lsp = ServerBenchmark(
'lsp-analysis-server',
'LSP Analysis Server',
LspAnalysisServerBenchmarkTest.new,
);
final String id;
final String name;
final AbstractBenchmarkTest Function() testConstructor;
new(this.id, this.name, this.testConstructor);
}