Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4093d08

Browse files
vsmenoncommit-bot@chromium.org
authored andcommitted
Revert "[dartdevc] record metrics"
This reverts commit 73347e0. This is breaking the internal build. TBR=grouma,sigmund Change-Id: Iad093ddb8c996cd65571d00b3d711453358a4f26 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139001 Reviewed-by: Vijay Menon <[email protected]> Commit-Queue: Vijay Menon <[email protected]>
1 parent 63bff1a commit 4093d08

File tree

4 files changed

+13
-135
lines changed

4 files changed

+13
-135
lines changed

pkg/dev_compiler/lib/js/legacy/dart_library.js

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,6 @@ if (!dart_library) {
2525
const libraryImports = Symbol('libraryImports');
2626
dart_library.libraryImports = libraryImports;
2727

28-
const _metrics = Symbol('metrics');
29-
const _logMetrics = false;
30-
31-
32-
// Returns a map from module name to various metrics for
33-
// module.
34-
function metrics() {
35-
var map = {};
36-
var keys = Array.from(_libraries.keys());
37-
for (var key of keys) {
38-
var lib = _libraries.get(key);
39-
map[lib._name] = lib._library[_metrics];
40-
}
41-
return map;
42-
}
43-
dart_library.metrics = metrics;
44-
45-
function _sortFn(key1, key2) {
46-
var t1 = _libraries.get(key1)._library[_metrics].loadTime;
47-
var t2 = _libraries.get(key2)._library[_metrics].loadTime;
48-
return t1 - t2;
49-
}
50-
51-
// Convenience method to print the metrics in the browser console
52-
// in CSV format.
53-
function metricsCsv() {
54-
var buffer = 'Module, JS Size, Dart Size, Load Time, Cumulative JS Size\n';
55-
var keys = Array.from(_libraries.keys());
56-
keys.sort(_sortFn);
57-
var cumulativeJsSize = 0;
58-
for (var key of keys) {
59-
var lib = _libraries.get(key);
60-
var jsSize = lib._library[_metrics].jsSize;
61-
cumulativeJsSize += jsSize;
62-
var dartSize = lib._library[_metrics].dartSize;
63-
var loadTime = lib._library[_metrics].loadTime;
64-
buffer += '"' + lib._name + '", ' + jsSize + ', ' + dartSize + ', ' + loadTime + ', ' + cumulativeJsSize+ '\n';
65-
}
66-
return buffer;
67-
}
68-
dart_library.metricsCsv = metricsCsv;
69-
7028
// Module support. This is a simplified module system for Dart.
7129
// Longer term, we can easily migrate to an existing JS module system:
7230
// ES6, AMD, RequireJS, ....
@@ -102,7 +60,7 @@ if (!dart_library) {
10260
let _reverseImports = new Map();
10361
class LibraryLoader {
10462

105-
constructor(name, defaultValue, imports, loader, data) {
63+
constructor(name, defaultValue, imports, loader) {
10664
imports.forEach(function (i) {
10765
let deps = _reverseImports.get(i);
10866
if (!deps) {
@@ -115,9 +73,6 @@ if (!dart_library) {
11573
this._library = defaultValue ? defaultValue : {};
11674
this._imports = imports;
11775
this._loader = loader;
118-
data.jsSize = loader.toString().length;
119-
data.loadTime = Infinity;
120-
this._library[_metrics] = data;
12176

12277
// Cyclic import detection
12378
this._state = LibraryLoader.NOT_LOADED;
@@ -153,26 +108,15 @@ if (!dart_library) {
153108

154109
if (this._name == 'dart_sdk') {
155110
// Eagerly load the SDK.
156-
library[_metrics].loadTime = window.performance.now();
157-
if (_logMetrics) console.time('Load ' + this._name);
158111
this._loader.apply(null, args);
159-
if (_logMetrics) console.timeEnd('Load ' + this._name);
160-
loader._loader = null;
161112
} else {
162113
// Load / parse other modules on demand.
163114
let done = false;
164115
this._library = new Proxy(library, {
165-
get: function(o, name) {
166-
if (name == _metrics) {
167-
return o[name];
168-
}
116+
get: function (o, name) {
169117
if (!done) {
170118
done = true;
171-
library[_metrics].loadTime = window.performance.now();
172-
if (_logMetrics) console.time('Load ' + loader._name);
173119
loader._loader.apply(null, args);
174-
if (_logMetrics) console.timeEnd('Load ' + loader._name);
175-
loader._loader = null;
176120
}
177121
return o[name];
178122
}
@@ -214,13 +158,13 @@ if (!dart_library) {
214158
deps.forEach(_invalidateLibrary);
215159
}
216160

217-
function library(name, defaultValue, imports, loader, data = {}) {
161+
function library(name, defaultValue, imports, loader) {
218162
let result = _libraries.get(name);
219163
if (result) {
220164
console.log('Re-loading ' + name);
221165
_invalidateLibrary(name);
222166
}
223-
result = new LibraryLoader(name, defaultValue, imports, loader, data);
167+
result = new LibraryLoader(name, defaultValue, imports, loader);
224168
_libraries.set(name, result);
225169
return result;
226170
}
@@ -302,6 +246,7 @@ if (!dart_library) {
302246

303247
/// Once the `onReloadStart()` completes, this finishes the restart.
304248
function finishHotRestart() {
249+
window.console.clear();
305250
if (clearState) {
306251
// This resets all initialized fields and clears type caches and other
307252
// temporary data structures used by the compiler/SDK.

pkg/dev_compiler/lib/src/compiler/module_builder.dart

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,10 @@ void addModuleFormatOptions(ArgParser argParser, {bool hide = true}) {
6868
/// structure as possible with the original. The transformation is a shallow one
6969
/// that affects the top-level module items, especially [ImportDeclaration]s and
7070
/// [ExportDeclaration]s.
71-
Program transformModuleFormat(ModuleFormat format, Program module,
72-
{Expression compileTimeStatistics}) {
71+
Program transformModuleFormat(ModuleFormat format, Program module) {
7372
switch (format) {
7473
case ModuleFormat.ddc:
75-
// Legacy format always generates output compatible with single file mode.
76-
return DdcModuleBuilder(
77-
compileTimeStatistics: compileTimeStatistics ?? LiteralNull())
78-
.build(module);
74+
return DdcModuleBuilder().build(module);
7975
case ModuleFormat.common:
8076
return CommonJSModuleBuilder().build(module);
8177
case ModuleFormat.amd:
@@ -132,9 +128,6 @@ abstract class _ModuleBuilder {
132128
/// Generates modules for with our DDC `dart_library.js` loading mechanism.
133129
// TODO(jmesserly): remove this and replace with something that interoperates.
134130
class DdcModuleBuilder extends _ModuleBuilder {
135-
final Expression compileTimeStatistics;
136-
DdcModuleBuilder({this.compileTimeStatistics});
137-
138131
Program build(Program module) {
139132
// Collect imports/exports/statements.
140133
visitProgram(module);
@@ -192,13 +185,12 @@ class DdcModuleBuilder extends _ModuleBuilder {
192185
js.fun("function(#) { 'use strict'; #; }", [parameters, statements]),
193186
true);
194187

195-
var moduleDef = js.statement('dart_library.library(#, #, #, #, #)', [
188+
var moduleDef = js.statement('dart_library.library(#, #, #, #)', [
196189
js.string(module.name, "'"),
197190
LiteralNull(),
198191
js.commentExpression(
199192
'Imports', ArrayInitializer(importNames, multiline: true)),
200-
resultModule,
201-
compileTimeStatistics
193+
resultModule
202194
]);
203195
return Program(<ModuleItem>[moduleDef]);
204196
}

pkg/dev_compiler/lib/src/kernel/command.dart

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,6 @@ Future<CompilerResult> _compile(List<String> args,
401401

402402
var jsModule = compiler.emitModule(compiledLibraries);
403403

404-
var statistics = computeCompileTimeStatistics(compiledLibraries);
405-
406404
// Also the old Analyzer backend had some code to make debugging better when
407405
// --single-out-file is used, but that option does not appear to be used by
408406
// any of our build systems.
@@ -417,8 +415,7 @@ Future<CompilerResult> _compile(List<String> args,
417415
jsUrl: p.toUri(output).toString(),
418416
mapUrl: p.toUri(output + '.map').toString(),
419417
customScheme: multiRootScheme,
420-
multiRootOutputPath: multiRootOutputPath,
421-
compileTimeStatistics: statistics);
418+
multiRootOutputPath: multiRootOutputPath);
422419

423420
outFiles.add(file.writeAsString(jsCode.code));
424421
if (jsCode.sourceMap != null) {
@@ -528,40 +525,6 @@ Future<CompilerResult> compileSdkFromDill(List<String> args) async {
528525
return CompilerResult(0);
529526
}
530527

531-
// Compute statistics (e.g., code size) to embed in the generated JavaScript
532-
// for this module.
533-
//
534-
// This is intended to be used by our build/debug tools to gather metrics.
535-
// See pkg/dev_compiler/lib/js/legacy/dart_library.js for runtime code that
536-
// reads this.
537-
//
538-
// These keys (see corresponding logic in dart_library.js) include:
539-
// - dartSize: <size of Dart input code in bytes>
540-
// TODO(vsm): Add source map size.
541-
//
542-
// TODO(vsm): Ideally, this information is never sent to the browser. I.e.,
543-
// our runtime metrics gathering would obtain this information from the
544-
// compilation server, not the browser. We don't yet have the infra for that.
545-
js_ast.ObjectInitializer computeCompileTimeStatistics(Component component) {
546-
var dartSize = 0;
547-
var uriToSource = component.uriToSource;
548-
for (var lib in component.libraries) {
549-
var libUri = lib.fileUri;
550-
var source = uriToSource[libUri];
551-
dartSize += source.source.length;
552-
for (var part in lib.parts) {
553-
var partUri = libUri.resolve(part.partUri);
554-
var partSource = uriToSource[partUri];
555-
// TODO(vsm): If we're compiling from dill, `partSource.source` can be
556-
// `null`. Today, we only do this for the SDK externally, which does
557-
// not go through this path.
558-
dartSize += partSource.source.length;
559-
}
560-
}
561-
return js_ast.ObjectInitializer(
562-
[js_ast.Property(js.string('dartSize'), js.number(dartSize))]);
563-
}
564-
565528
/// The output of compiling a JavaScript module in a particular format.
566529
/// This was copied from module_compiler.dart class "JSModuleCode".
567530
class JSCode {
@@ -591,8 +554,7 @@ JSCode jsProgramToCode(js_ast.Program moduleTree, ModuleFormat format,
591554
String mapUrl,
592555
String sourceMapBase,
593556
String customScheme,
594-
String multiRootOutputPath,
595-
js_ast.Expression compileTimeStatistics}) {
557+
String multiRootOutputPath}) {
596558
var opts = js_ast.JavaScriptPrintingOptions(
597559
allowKeywordsInProperties: true, allowSingleLineIfStatements: true);
598560
js_ast.SimpleJavaScriptPrintingContext printer;
@@ -605,8 +567,7 @@ JSCode jsProgramToCode(js_ast.Program moduleTree, ModuleFormat format,
605567
printer = js_ast.SimpleJavaScriptPrintingContext();
606568
}
607569

608-
var tree = transformModuleFormat(format, moduleTree,
609-
compileTimeStatistics: compileTimeStatistics);
570+
var tree = transformModuleFormat(format, moduleTree);
610571
tree.accept(
611572
js_ast.Printer(opts, printer, localNamer: js_ast.TemporaryNamer(tree)));
612573

pkg/dev_compiler/tool/kernel_sdk.dart

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import 'package:build_integration/file_system/multi_root.dart';
1111
import 'package:dev_compiler/src/compiler/module_builder.dart';
1212
import 'package:dev_compiler/src/compiler/shared_command.dart'
1313
show SharedCompilerOptions;
14-
import 'package:dev_compiler/src/js_ast/js_ast.dart' as js_ast;
15-
import 'package:dev_compiler/src/js_ast/js_ast.dart' show js;
1614
import 'package:dev_compiler/src/kernel/target.dart';
1715
import 'package:dev_compiler/src/kernel/command.dart';
1816
import 'package:dev_compiler/src/kernel/compiler.dart';
@@ -89,23 +87,6 @@ Future main(List<String> args) async {
8987
var compilerResult = await kernelForModule(inputs, options);
9088
var component = compilerResult.component;
9189

92-
// TODO(vsm): This is repetitive with kernel/command.dart. This whole
93-
// file should be removed in favor of a direct invocation.
94-
var dartSize = 0;
95-
var uriToSource = component.uriToSource;
96-
for (var lib in component.libraries) {
97-
var libUri = lib.fileUri;
98-
var source = uriToSource[libUri];
99-
dartSize += source.source.length;
100-
for (var part in lib.parts) {
101-
var partUri = libUri.resolve(part.partUri);
102-
var partSource = uriToSource[partUri];
103-
dartSize += partSource.source.length;
104-
}
105-
}
106-
var statistics = js_ast.ObjectInitializer(
107-
[js_ast.Property(js.string('dartSize'), js.number(dartSize))]);
108-
10990
var outputDir = p.dirname(outputPath);
11091
await Directory(outputDir).create(recursive: true);
11192
await writeComponentToBinary(component, outputPath);
@@ -135,8 +116,7 @@ Future main(List<String> args) async {
135116
jsUrl: jsPath,
136117
mapUrl: mapPath,
137118
buildSourceMap: true,
138-
customScheme: customScheme,
139-
compileTimeStatistics: statistics);
119+
customScheme: customScheme);
140120
await File(jsPath).writeAsString(jsCode.code);
141121
await File(mapPath).writeAsString(json.encode(jsCode.sourceMap));
142122
}

0 commit comments

Comments
 (0)