[kernel] Wrap debugPath in assert in BinaryBuilder

The code for reading dill files via dart has a "debugPath" list that is
continously added and removed to in order to be able to debug what went
wrong if something goes wrong (e.g. if the dill file is invalid or the
reading code is wrong etc).

This CL wraps the updates of this list in assert so that we don't pay
for what we don't use in the general case. In a debug setting we can get
the functionality back via --checked.

On a benchmark of 10 runs, the time it takes to read vm_outline.dill 100
times after a 2 second warmup changes by -2.77% +/- 1.21%.

Bug:
Change-Id: I643b8dd778972621046fe76b536fd95e9bb66d1c
Reviewed-on: https://dart-review.googlesource.com/18820
Reviewed-by: Peter von der Ahé <ahe@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
This commit is contained in:
Jens Johansen 2017-11-22 09:29:57 +00:00 committed by commit-bot@chromium.org
parent 80992a5a09
commit ca877c964f

View file

@ -621,7 +621,8 @@ class BinaryBuilder {
library.fileUri = fileUri;
}
debugPath.add(library.name ?? library.importUri?.toString() ?? 'library');
assert(((_) => true)(debugPath
.add(library.name ?? library.importUri?.toString() ?? 'library')));
if (shouldWriteData) {
_fillTreeNodeList(
@ -646,7 +647,7 @@ class BinaryBuilder {
}, library);
_byteOffset = procedureOffsets.last;
debugPath.removeLast();
assert(((_) => true)(debugPath.removeLast()));
_currentLibrary = null;
return library;
}
@ -779,7 +780,7 @@ class BinaryBuilder {
var name = readStringOrNullIfEmpty();
var fileUri = readUriReference();
var annotations = readAnnotationList(node);
debugPath.add(node.name ?? 'normal-class');
assert(((_) => true)(debugPath.add(node.name ?? 'normal-class')));
readAndPushTypeParameterList(node.typeParameters, node);
var supertype = readSupertypeOption();
var mixedInType = readSupertypeOption();
@ -797,7 +798,7 @@ class BinaryBuilder {
}, node);
_byteOffset = procedureOffsets.last;
typeParameterStack.length = 0;
debugPath.removeLast();
assert(debugPath.removeLast() != null);
if (shouldWriteData) {
node.name = name;
node.fileUri = fileUri;
@ -839,11 +840,11 @@ class BinaryBuilder {
var name = readName();
var fileUri = readUriReference();
var annotations = readAnnotationList(node);
debugPath.add(node.name?.name ?? 'field');
assert(((_) => true)(debugPath.add(node.name?.name ?? 'field')));
var type = readDartType();
var initializer = readExpressionOption();
int transformerFlags = getAndResetTransformerFlags();
debugPath.removeLast();
assert(((_) => true)(debugPath.removeLast()));
if (shouldWriteData) {
node.fileOffset = fileOffset;
node.fileEndOffset = fileEndOffset;
@ -875,7 +876,7 @@ class BinaryBuilder {
var flags = readByte();
var name = readName();
var annotations = readAnnotationList(node);
debugPath.add(node.name?.name ?? 'constructor');
assert(((_) => true)(debugPath.add(node.name?.name ?? 'constructor')));
var function = readFunctionNode(false, -1);
pushVariableDeclarations(function.positionalParameters);
pushVariableDeclarations(function.namedParameters);
@ -886,7 +887,7 @@ class BinaryBuilder {
}
variableStack.length = 0;
var transformerFlags = getAndResetTransformerFlags();
debugPath.removeLast();
assert(((_) => true)(debugPath.removeLast()));
if (shouldWriteData) {
node.fileOffset = fileOffset;
node.fileEndOffset = fileEndOffset;
@ -917,7 +918,7 @@ class BinaryBuilder {
var name = readName();
var fileUri = readUriReference();
var annotations = readAnnotationList(node);
debugPath.add(node.name?.name ?? 'procedure');
assert(((_) => true)(debugPath.add(node.name?.name ?? 'procedure')));
int functionNodeSize = endOffset - _byteOffset;
// Read small factories up front. Postpone everything else.
bool readFunctionNodeNow =
@ -925,7 +926,7 @@ class BinaryBuilder {
_disableLazyReading;
var function = readFunctionNodeOption(!readFunctionNodeNow, endOffset);
var transformerFlags = getAndResetTransformerFlags();
debugPath.removeLast();
assert(((_) => true)(debugPath.removeLast()));
if (shouldWriteData) {
node.fileOffset = fileOffset;
node.fileEndOffset = fileEndOffset;