Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: pkg/analyzer/lib/src/dart/analysis/driver.dart

Issue 2540403002: Move running tasks for fixed time to the scheduler. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/analysis/driver.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index a84d458d3313eb9c5b74f2d59c6ea23cce8730fc..35698f9a36e22ef0660de51e65f42513d2bb535a 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -977,6 +977,7 @@ class AnalysisDriverScheduler {
* priority first.
*/
Future<Null> _run() async {
+ Stopwatch timer = new Stopwatch()..start();
PerformanceLogSection analysisSection;
while (true) {
// Pump the event queue to allow IO and other asynchronous data
@@ -988,7 +989,14 @@ class AnalysisDriverScheduler {
// analysis or other data processing tasks are starving. Ideally we
// would need to be able to set priority of (continuous) asynchronous
// tasks.
- await _pumpEventQueue(128);
+ //
+ // Relinquishing execution flow and running event loop after every task
+ // has too much overhead. Instead we use a fixed length of time, so we
+ // can spend less time overall and still respond quick enough.
+ if (timer.elapsedMilliseconds > 2) {
Brian Wilkerson 2016/12/01 14:36:38 I think it would be a good thing to define some co
scheglov 2016/12/01 16:55:06 Done.
+ await _pumpEventQueue(128);
+ timer.reset();
+ }
await _hasWork.signal;
@@ -1266,37 +1274,30 @@ class _FilesReferencingNameTask {
_FilesReferencingNameTask(this.driver, this.name);
/**
- * Perform work for a fixed length of time, and either complete the
- * [completer] and return `true` to indicate that the task is done, return
- * `false` to indicate that the task should continue to be run.
- *
- * Relinquishing execution flow and running event loop after every file
- * works, but has too much overhead. Instead we use a fixed length of time,
- * so we can spend less time overall and keep quick enough response time.
+ * Perform a single piece of work, and either complete the [completer] and
+ * return `true` to indicate that the task is done, return `false` to indicate
+ * that the task should continue to be run.
*/
Future<bool> perform() async {
- Stopwatch timer = new Stopwatch()..start();
- while (timer.elapsedMilliseconds < 5) {
- // Prepare files to check.
- if (filesToCheck.isEmpty) {
- Set<String> newFiles = driver.addedFiles.difference(checkedFiles);
- filesToCheck.addAll(newFiles);
- }
+ // Prepare files to check.
+ if (filesToCheck.isEmpty) {
+ Set<String> newFiles = driver.addedFiles.difference(checkedFiles);
+ filesToCheck.addAll(newFiles);
+ }
- // If no more files to check, complete and done.
- if (filesToCheck.isEmpty) {
- completer.complete(referencingFiles);
- return true;
- }
+ // If no more files to check, complete and done.
+ if (filesToCheck.isEmpty) {
+ completer.complete(referencingFiles);
+ return true;
+ }
- // Check the next file.
- String path = filesToCheck.removeLast();
- FileState file = driver._fsState.getFileForPath(path);
- if (file.referencedNames.contains(name)) {
- referencingFiles.add(path);
- }
- checkedFiles.add(path);
+ // Check the next file.
+ String path = filesToCheck.removeLast();
+ FileState file = driver._fsState.getFileForPath(path);
+ if (file.referencedNames.contains(name)) {
+ referencingFiles.add(path);
}
+ checkedFiles.add(path);
// We're not done yet.
return false;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698