Skip to content

Commit

Permalink
Version 3.4.0-247.0.dev
Browse files Browse the repository at this point in the history
Merge 1b5368f into dev
  • Loading branch information
Dart CI committed Mar 19, 2024
2 parents 91dc69b + 1b5368f commit 7c64e31
Show file tree
Hide file tree
Showing 29 changed files with 829 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scorecards-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

steps:
- name: "Checkout code"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
with:
persist-credentials: false

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/third-party-deps-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
contents: read
steps:
- name: "Checkout code"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
with:
persist-credentials: false
- name: "setup python"
Expand Down
114 changes: 114 additions & 0 deletions pkg/analysis_server/tool/code_completion/benchmark/flutter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright (c) 2024, 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 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/file_system/overlay_file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/src/util/performance/operation_performance.dart';

import 'sliding_statistics.dart';

/// A tool to see the current performance of code completion at an interesting
/// location. To see details, run it with `--observe:5000` and then use
/// DevTools CPU profiler.
///
/// Currently this is not a tool to track performance, it does not record it
/// anywhere.
///
/// Update the marked code as necessary to construct a case for checking
/// performance. The code below is just one example that we saw to have
/// significant cost.
///
/// Don't forget to update [flutterPackagePath].
Future<void> main() async {
await _runForever(
path: '$flutterPackagePath/lib/test.dart',
markedCode: r'''
import 'package:flutter/widgets.dart';
Widget x = ^;
''',
);
}

const String flutterEnvironmentPath =
'/Users/scheglov/dart/flutter_elements/environment';

/// This should be the path of the `package:flutter` in a local checkout.
/// You don't have to use [flutterEnvironmentPath] from above.
const String flutterPackagePath = '$flutterEnvironmentPath/packages/flutter';

Future<void> _runForever({
required String path,
required String markedCode,
}) async {
final offset = markedCode.indexOf('^');
if (offset == -1) {
throw ArgumentError('No ^ marker');
}

final rawCode =
markedCode.substring(0, offset) + markedCode.substring(offset + 1);
if (rawCode.contains('^')) {
throw ArgumentError('Duplicate ^ marker');
}

final resourceProvider = OverlayResourceProvider(
PhysicalResourceProvider.INSTANCE,
);

resourceProvider.setOverlay(
path,
content: rawCode,
modificationStamp: -1,
);

var collection = AnalysisContextCollectionImpl(
resourceProvider: resourceProvider,
includedPaths: [path],
sdkPath: '/Users/scheglov/Applications/dart-sdk',
);
var analysisContext = collection.contextFor(path);
var analysisSession = analysisContext.currentSession;
var unitResult = await analysisSession.getResolvedUnit(path);
unitResult as ResolvedUnitResult;

var dartRequest = DartCompletionRequest.forResolvedUnit(
resolvedUnit: unitResult,
offset: offset,
);

final statistics = SlidingStatistics(100);
while (true) {
var timer = Stopwatch()..start();
var budget = CompletionBudget(Duration(seconds: 30));
List<CompletionSuggestionBuilder> suggestions = [];
for (var i = 0; i < 10; i++) {
suggestions = await DartCompletionManager(
budget: budget,
notImportedSuggestions: NotImportedSuggestions(),
).computeSuggestions(
dartRequest,
OperationPerformanceImpl('<root>'),
useFilter: false,
);
}

final responseTime = timer.elapsedMilliseconds;
statistics.add(responseTime);
if (statistics.isReady) {
print(
'[${DateTime.now().millisecondsSinceEpoch}]'
'[time: $responseTime ms][mean: ${statistics.mean.toStringAsFixed(1)}]'
'[stdDev: ${statistics.standardDeviation.toStringAsFixed(3)}]'
'[min: ${statistics.min.toStringAsFixed(1)}]'
'[max: ${statistics.max.toStringAsFixed(1)}]',
);
} else {
print('[time: $responseTime ms][suggestions: ${suggestions.length}]');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2024, 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:math';
import 'dart:typed_data';

class SlidingStatistics {
final Uint32List _values;
int _index = 0;
bool _isReady = false;

SlidingStatistics(int length) : _values = Uint32List(length);

bool get isReady => _isReady;

int get max {
var result = 0;
for (final value in _values) {
if (value > result) {
result = value;
}
}
return result;
}

double get mean {
assert(isReady);
var sum = 0.0;
for (final value in _values) {
sum += value;
}
return sum / _values.length;
}

int get min {
var result = 1 << 20;
for (final value in _values) {
if (value < result) {
result = value;
}
}
return result;
}

double get standardDeviation {
assert(isReady);
final mean = this.mean;
var sum = 0.0;
for (final value in _values) {
final diff = value - mean;
sum += diff * diff;
}
return sqrt(sum / _values.length);
}

void add(int value) {
_values[_index] = value;
_index++;
if (_index == _values.length) {
_isReady = true;
}
_index %= _values.length;
}
}
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import 'package:meta/meta.dart';
// TODO(scheglov): Clean up the list of implicitly analyzed files.
class AnalysisDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 351;
static const int DATA_VERSION = 353;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down
24 changes: 12 additions & 12 deletions pkg/analyzer/lib/src/dart/element/display_string_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class ElementDisplayStringBuilder {
}

void writeConstructorElement(ConstructorElement element) {
if (element.isAugmentation) {
_write('augment ');
}

_writeType(element.returnType);
_write(' ');

Expand All @@ -88,25 +92,17 @@ class ElementDisplayStringBuilder {
}

void writeEnumElement(EnumElement element) {
if (element.isAugmentation) {
_write('augment ');
}

_write('enum ');
_write(element.displayName);
_writeTypeParameters(element.typeParameters);
_writeTypesIfNotEmpty(' with ', element.mixins);
_writeTypesIfNotEmpty(' implements ', element.interfaces);
}

// void writePropertyAccessor(PropertyAccessorElement element) {
// var variable = element.variable2;
// if (variable == null) {
// // builder.;
// }
//
// writeExecutableElement(
// element,
// (element.isGetter ? 'get ' : 'set ') + variable2.displayName,
// );
// }

void writeExecutableElement(ExecutableElement element, String name) {
if (element.isAugmentation) {
_write('augment ');
Expand Down Expand Up @@ -135,6 +131,10 @@ class ElementDisplayStringBuilder {
}

void writeExtensionElement(ExtensionElement element) {
if (element.isAugmentation) {
_write('augment ');
}

_write('extension');
if (element.displayName.isNotEmpty) {
_write(' ');
Expand Down
7 changes: 7 additions & 0 deletions pkg/analyzer/lib/src/summary2/bundle_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,13 @@ class TopLevelVariableElementLinkedData
);
element.macroDiagnostics = reader.readMacroDiagnostics();
element.type = reader.readRequiredType();

final augmentationTarget = reader.readElement();
if (augmentationTarget is TopLevelVariableElementImpl) {
augmentationTarget.augmentation = element;
element.augmentationTarget = augmentationTarget;
}

if (element is ConstTopLevelVariableElementImpl) {
var initializer = reader._readOptionalExpression();
if (initializer != null) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/analyzer/lib/src/summary2/bundle_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ class BundleWriter {
_resolutionSink._writeAnnotationList(element.metadata);
_resolutionSink.writeMacroDiagnostics(element.macroDiagnostics);
_resolutionSink.writeType(element.type);

_resolutionSink.writeElement(element.augmentationTarget);
if (element.isAugmentation) {
_propertyAugmentations.add(element);
}

_resolutionSink._writeOptionalNode(element.constantInitializer);
}

Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/src/summary2/element_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
}

element.hasInitializer = variable.initializer != null;
element.isAugmentation = node.augmentKeyword != null;
element.isConst = node.variables.isConst;
element.isExternal = node.externalKeyword != null;
element.isFinal = node.variables.isFinal;
Expand Down
18 changes: 18 additions & 0 deletions pkg/analyzer/lib/src/test_utilities/resource_provider_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:io';

import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:path/path.dart' as path;
import 'package:path/path.dart';
Expand Down Expand Up @@ -146,11 +147,28 @@ mixin ResourceProviderMixin {
return newFile(path, content);
}

File newPackageConfigJsonFileFromBuilder(
String directoryPath,
PackageConfigFileBuilder builder,
) {
final content = builder.toContent(toUriStr: toUriStr);
return newPackageConfigJsonFile(directoryPath, content);
}

File newPubspecYamlFile(String directoryPath, String content) {
String path = join(directoryPath, file_paths.pubspecYaml);
return newFile(path, content);
}

void newSinglePackageConfigJsonFile({
required String packagePath,
required String name,
}) {
final builder = PackageConfigFileBuilder()
..add(name: name, rootPath: packagePath);
newPackageConfigJsonFileFromBuilder(packagePath, builder);
}

Uri toUri(String path) {
path = convertPath(path);
return resourceProvider.pathContext.toUri(path);
Expand Down
Loading

0 comments on commit 7c64e31

Please sign in to comment.