From 5c0c41cc689c8abb2cbc6bd83daf131f1bef3549 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Wed, 3 Jun 2020 04:20:04 +0000 Subject: [PATCH] Add CiderCompletionResult.performance Change-Id: I5df913afc99fc253282611472dc3ff48b9abb8c8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149785 Reviewed-by: Keerti Parthasarathy Commit-Queue: Konstantin Shcheglov --- .../lib/src/cider/completion.dart | 65 ++++++++++--------- .../test/src/cider/completion_test.dart | 15 ----- 2 files changed, 35 insertions(+), 45 deletions(-) diff --git a/pkg/analysis_server/lib/src/cider/completion.dart b/pkg/analysis_server/lib/src/cider/completion.dart index 068faccbb36..b6e249dc9cc 100644 --- a/pkg/analysis_server/lib/src/cider/completion.dart +++ b/pkg/analysis_server/lib/src/cider/completion.dart @@ -26,7 +26,6 @@ import 'package:meta/meta.dart'; /// example types and elements. class CiderCompletionCache { final Map _importedLibraries = {}; - _LastCompletionResult _lastResult; } class CiderCompletionComputer { @@ -56,30 +55,23 @@ class CiderCompletionComputer { @required int line, @required int column, }) async { + var getFileTimer = Stopwatch()..start(); var fileContext = _logger.run('Get file $path', () { - return _fileResolver.getFileContext(path); + try { + return _fileResolver.getFileContext(path); + } finally { + getFileTimer.stop(); + } }); var file = fileContext.file; - var resolvedSignature = _logger.run('Get signature', () { - return file.resolvedSignature; - }); - var lineInfo = file.lineInfo; var offset = lineInfo.getOffsetOfLine(line) + column; - // If the same file, in the same state as the last time, reuse the result. - var lastResult = _cache._lastResult; - if (lastResult != null && - lastResult.path == path && - lastResult.signature == resolvedSignature && - lastResult.offset == offset) { - _logger.writeln('Use the last completion result.'); - return lastResult.result; - } - + var resolutionTimer = Stopwatch()..start(); var resolvedUnit = _fileResolver.resolve(path); + resolutionTimer.stop(); var completionRequest = CompletionRequestImpl( resolvedUnit, @@ -129,10 +121,13 @@ class CiderCompletionComputer { }); var result = CiderCompletionResult._( - suggestions, CiderPosition(line, column - filter._pattern.length)); - - _cache._lastResult = - _LastCompletionResult(path, resolvedSignature, offset, result); + suggestions: suggestions, + performance: CiderCompletionPerformance( + file: getFileTimer.elapsed, + resolution: resolutionTimer.elapsed, + ), + prefixStart: CiderPosition(line, column - filter._pattern.length), + ); return result; } @@ -196,15 +191,34 @@ class CiderCompletionComputer { } } +class CiderCompletionPerformance { + /// The elapsed time for file access. + final Duration file; + + /// The elapsed time for resolution. + final Duration resolution; + + CiderCompletionPerformance({ + @required this.file, + @required this.resolution, + }); +} + class CiderCompletionResult { final List suggestions; + final CiderCompletionPerformance performance; + /// The start of the range that should be replaced with the suggestion. This /// position always precedes or is the same as the cursor provided in the /// completion request. final CiderPosition prefixStart; - CiderCompletionResult._(this.suggestions, this.prefixStart); + CiderCompletionResult._({ + @required this.suggestions, + @required this.performance, + @required this.prefixStart, + }); } class CiderPosition { @@ -289,12 +303,3 @@ class _FuzzyScoredSuggestion { _FuzzyScoredSuggestion(this.suggestion, this.score); } - -class _LastCompletionResult { - final String path; - final String signature; - final int offset; - final CiderCompletionResult result; - - _LastCompletionResult(this.path, this.signature, this.offset, this.result); -} diff --git a/pkg/analysis_server/test/src/cider/completion_test.dart b/pkg/analysis_server/test/src/cider/completion_test.dart index c83ac3b85ee..0ab4c89ff03 100644 --- a/pkg/analysis_server/test/src/cider/completion_test.dart +++ b/pkg/analysis_server/test/src/cider/completion_test.dart @@ -75,21 +75,6 @@ import 'dart:math'; expect(_completionResult.prefixStart.column, 0); } - Future test_compute_sameSignature_sameResult() async { - await _compute(r''' -var a = ^; -'''); - var lastResult = _completionResult; - - // Ask for completion using new resolver and computer. - // But the file signature is the same, so the same result. - _createFileResolver(); - await _compute(r''' -var a = ^; -'''); - expect(_completionResult, same(lastResult)); - } - Future test_compute_updateImportedLibrary() async { var aPath = convertPath('/workspace/dart/test/lib/a.dart'); newFile(aPath, content: r'''