Skip to content

Commit

Permalink
Revert "[dartdevc] record metrics"
Browse files Browse the repository at this point in the history
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 <vsm@google.com>
Commit-Queue: Vijay Menon <vsm@google.com>
  • Loading branch information
vsmenon authored and commit-bot@chromium.org committed Mar 11, 2020
1 parent 63bff1a commit 4093d08
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 135 deletions.
65 changes: 5 additions & 60 deletions pkg/dev_compiler/lib/js/legacy/dart_library.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,6 @@ if (!dart_library) {
const libraryImports = Symbol('libraryImports');
dart_library.libraryImports = libraryImports;

const _metrics = Symbol('metrics');
const _logMetrics = false;


// Returns a map from module name to various metrics for
// module.
function metrics() {
var map = {};
var keys = Array.from(_libraries.keys());
for (var key of keys) {
var lib = _libraries.get(key);
map[lib._name] = lib._library[_metrics];
}
return map;
}
dart_library.metrics = metrics;

function _sortFn(key1, key2) {
var t1 = _libraries.get(key1)._library[_metrics].loadTime;
var t2 = _libraries.get(key2)._library[_metrics].loadTime;
return t1 - t2;
}

// Convenience method to print the metrics in the browser console
// in CSV format.
function metricsCsv() {
var buffer = 'Module, JS Size, Dart Size, Load Time, Cumulative JS Size\n';
var keys = Array.from(_libraries.keys());
keys.sort(_sortFn);
var cumulativeJsSize = 0;
for (var key of keys) {
var lib = _libraries.get(key);
var jsSize = lib._library[_metrics].jsSize;
cumulativeJsSize += jsSize;
var dartSize = lib._library[_metrics].dartSize;
var loadTime = lib._library[_metrics].loadTime;
buffer += '"' + lib._name + '", ' + jsSize + ', ' + dartSize + ', ' + loadTime + ', ' + cumulativeJsSize+ '\n';
}
return buffer;
}
dart_library.metricsCsv = metricsCsv;

// Module support. This is a simplified module system for Dart.
// Longer term, we can easily migrate to an existing JS module system:
// ES6, AMD, RequireJS, ....
Expand Down Expand Up @@ -102,7 +60,7 @@ if (!dart_library) {
let _reverseImports = new Map();
class LibraryLoader {

constructor(name, defaultValue, imports, loader, data) {
constructor(name, defaultValue, imports, loader) {
imports.forEach(function (i) {
let deps = _reverseImports.get(i);
if (!deps) {
Expand All @@ -115,9 +73,6 @@ if (!dart_library) {
this._library = defaultValue ? defaultValue : {};
this._imports = imports;
this._loader = loader;
data.jsSize = loader.toString().length;
data.loadTime = Infinity;
this._library[_metrics] = data;

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

if (this._name == 'dart_sdk') {
// Eagerly load the SDK.
library[_metrics].loadTime = window.performance.now();
if (_logMetrics) console.time('Load ' + this._name);
this._loader.apply(null, args);
if (_logMetrics) console.timeEnd('Load ' + this._name);
loader._loader = null;
} else {
// Load / parse other modules on demand.
let done = false;
this._library = new Proxy(library, {
get: function(o, name) {
if (name == _metrics) {
return o[name];
}
get: function (o, name) {
if (!done) {
done = true;
library[_metrics].loadTime = window.performance.now();
if (_logMetrics) console.time('Load ' + loader._name);
loader._loader.apply(null, args);
if (_logMetrics) console.timeEnd('Load ' + loader._name);
loader._loader = null;
}
return o[name];
}
Expand Down Expand Up @@ -214,13 +158,13 @@ if (!dart_library) {
deps.forEach(_invalidateLibrary);
}

function library(name, defaultValue, imports, loader, data = {}) {
function library(name, defaultValue, imports, loader) {
let result = _libraries.get(name);
if (result) {
console.log('Re-loading ' + name);
_invalidateLibrary(name);
}
result = new LibraryLoader(name, defaultValue, imports, loader, data);
result = new LibraryLoader(name, defaultValue, imports, loader);
_libraries.set(name, result);
return result;
}
Expand Down Expand Up @@ -302,6 +246,7 @@ if (!dart_library) {

/// Once the `onReloadStart()` completes, this finishes the restart.
function finishHotRestart() {
window.console.clear();
if (clearState) {
// This resets all initialized fields and clears type caches and other
// temporary data structures used by the compiler/SDK.
Expand Down
16 changes: 4 additions & 12 deletions pkg/dev_compiler/lib/src/compiler/module_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,10 @@ void addModuleFormatOptions(ArgParser argParser, {bool hide = true}) {
/// structure as possible with the original. The transformation is a shallow one
/// that affects the top-level module items, especially [ImportDeclaration]s and
/// [ExportDeclaration]s.
Program transformModuleFormat(ModuleFormat format, Program module,
{Expression compileTimeStatistics}) {
Program transformModuleFormat(ModuleFormat format, Program module) {
switch (format) {
case ModuleFormat.ddc:
// Legacy format always generates output compatible with single file mode.
return DdcModuleBuilder(
compileTimeStatistics: compileTimeStatistics ?? LiteralNull())
.build(module);
return DdcModuleBuilder().build(module);
case ModuleFormat.common:
return CommonJSModuleBuilder().build(module);
case ModuleFormat.amd:
Expand Down Expand Up @@ -132,9 +128,6 @@ abstract class _ModuleBuilder {
/// Generates modules for with our DDC `dart_library.js` loading mechanism.
// TODO(jmesserly): remove this and replace with something that interoperates.
class DdcModuleBuilder extends _ModuleBuilder {
final Expression compileTimeStatistics;
DdcModuleBuilder({this.compileTimeStatistics});

Program build(Program module) {
// Collect imports/exports/statements.
visitProgram(module);
Expand Down Expand Up @@ -192,13 +185,12 @@ class DdcModuleBuilder extends _ModuleBuilder {
js.fun("function(#) { 'use strict'; #; }", [parameters, statements]),
true);

var moduleDef = js.statement('dart_library.library(#, #, #, #, #)', [
var moduleDef = js.statement('dart_library.library(#, #, #, #)', [
js.string(module.name, "'"),
LiteralNull(),
js.commentExpression(
'Imports', ArrayInitializer(importNames, multiline: true)),
resultModule,
compileTimeStatistics
resultModule
]);
return Program(<ModuleItem>[moduleDef]);
}
Expand Down
45 changes: 3 additions & 42 deletions pkg/dev_compiler/lib/src/kernel/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,6 @@ Future<CompilerResult> _compile(List<String> args,

var jsModule = compiler.emitModule(compiledLibraries);

var statistics = computeCompileTimeStatistics(compiledLibraries);

// Also the old Analyzer backend had some code to make debugging better when
// --single-out-file is used, but that option does not appear to be used by
// any of our build systems.
Expand All @@ -417,8 +415,7 @@ Future<CompilerResult> _compile(List<String> args,
jsUrl: p.toUri(output).toString(),
mapUrl: p.toUri(output + '.map').toString(),
customScheme: multiRootScheme,
multiRootOutputPath: multiRootOutputPath,
compileTimeStatistics: statistics);
multiRootOutputPath: multiRootOutputPath);

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

// Compute statistics (e.g., code size) to embed in the generated JavaScript
// for this module.
//
// This is intended to be used by our build/debug tools to gather metrics.
// See pkg/dev_compiler/lib/js/legacy/dart_library.js for runtime code that
// reads this.
//
// These keys (see corresponding logic in dart_library.js) include:
// - dartSize: <size of Dart input code in bytes>
// TODO(vsm): Add source map size.
//
// TODO(vsm): Ideally, this information is never sent to the browser. I.e.,
// our runtime metrics gathering would obtain this information from the
// compilation server, not the browser. We don't yet have the infra for that.
js_ast.ObjectInitializer computeCompileTimeStatistics(Component component) {
var dartSize = 0;
var uriToSource = component.uriToSource;
for (var lib in component.libraries) {
var libUri = lib.fileUri;
var source = uriToSource[libUri];
dartSize += source.source.length;
for (var part in lib.parts) {
var partUri = libUri.resolve(part.partUri);
var partSource = uriToSource[partUri];
// TODO(vsm): If we're compiling from dill, `partSource.source` can be
// `null`. Today, we only do this for the SDK externally, which does
// not go through this path.
dartSize += partSource.source.length;
}
}
return js_ast.ObjectInitializer(
[js_ast.Property(js.string('dartSize'), js.number(dartSize))]);
}

/// The output of compiling a JavaScript module in a particular format.
/// This was copied from module_compiler.dart class "JSModuleCode".
class JSCode {
Expand Down Expand Up @@ -591,8 +554,7 @@ JSCode jsProgramToCode(js_ast.Program moduleTree, ModuleFormat format,
String mapUrl,
String sourceMapBase,
String customScheme,
String multiRootOutputPath,
js_ast.Expression compileTimeStatistics}) {
String multiRootOutputPath}) {
var opts = js_ast.JavaScriptPrintingOptions(
allowKeywordsInProperties: true, allowSingleLineIfStatements: true);
js_ast.SimpleJavaScriptPrintingContext printer;
Expand All @@ -605,8 +567,7 @@ JSCode jsProgramToCode(js_ast.Program moduleTree, ModuleFormat format,
printer = js_ast.SimpleJavaScriptPrintingContext();
}

var tree = transformModuleFormat(format, moduleTree,
compileTimeStatistics: compileTimeStatistics);
var tree = transformModuleFormat(format, moduleTree);
tree.accept(
js_ast.Printer(opts, printer, localNamer: js_ast.TemporaryNamer(tree)));

Expand Down
22 changes: 1 addition & 21 deletions pkg/dev_compiler/tool/kernel_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import 'package:build_integration/file_system/multi_root.dart';
import 'package:dev_compiler/src/compiler/module_builder.dart';
import 'package:dev_compiler/src/compiler/shared_command.dart'
show SharedCompilerOptions;
import 'package:dev_compiler/src/js_ast/js_ast.dart' as js_ast;
import 'package:dev_compiler/src/js_ast/js_ast.dart' show js;
import 'package:dev_compiler/src/kernel/target.dart';
import 'package:dev_compiler/src/kernel/command.dart';
import 'package:dev_compiler/src/kernel/compiler.dart';
Expand Down Expand Up @@ -89,23 +87,6 @@ Future main(List<String> args) async {
var compilerResult = await kernelForModule(inputs, options);
var component = compilerResult.component;

// TODO(vsm): This is repetitive with kernel/command.dart. This whole
// file should be removed in favor of a direct invocation.
var dartSize = 0;
var uriToSource = component.uriToSource;
for (var lib in component.libraries) {
var libUri = lib.fileUri;
var source = uriToSource[libUri];
dartSize += source.source.length;
for (var part in lib.parts) {
var partUri = libUri.resolve(part.partUri);
var partSource = uriToSource[partUri];
dartSize += partSource.source.length;
}
}
var statistics = js_ast.ObjectInitializer(
[js_ast.Property(js.string('dartSize'), js.number(dartSize))]);

var outputDir = p.dirname(outputPath);
await Directory(outputDir).create(recursive: true);
await writeComponentToBinary(component, outputPath);
Expand Down Expand Up @@ -135,8 +116,7 @@ Future main(List<String> args) async {
jsUrl: jsPath,
mapUrl: mapPath,
buildSourceMap: true,
customScheme: customScheme,
compileTimeStatistics: statistics);
customScheme: customScheme);
await File(jsPath).writeAsString(jsCode.code);
await File(mapPath).writeAsString(json.encode(jsCode.sourceMap));
}
Expand Down

0 comments on commit 4093d08

Please sign in to comment.