[VM] Only run FFI transformation when dart:ffi is imported

Before this CL the FFI transformation was always run (for target VM),
so if for instance running dart2js (from source), e.g. like
`out/ReleaseX64/dart -DDFE_VERBOSE=true pkg/compiler/bin/dart2js.dart --help`
one could see how it spends something like 120-140 ms, which is
something along the lines of 2.5% of the entire request processing
(i.e. compile and serialization).

This CL first checks if dart:ffi is imported at all. If it's not the
transformation is skipped.
When compiling dart2js (where, at least currently, dart:ffi is not used)
this skips the transformation, thus saving the 120-140 ms (or ~2.5%).

All measurements on my machine. Your mileage may vary.

TEST=Existing tests.

Change-Id: Ia5d3d7b989f549ca5da257660c204e8c59f15d4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185543
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
Jens Johansen
2021-02-19 09:44:08 +00:00
committed by commit-bot@chromium.org
parent 357e83e44d
commit ad596359a6
2 changed files with 38 additions and 11 deletions
+24 -11
View File
@@ -21,6 +21,7 @@ import 'package:kernel/vm/constants_native_effects.dart'
import '../transformations/call_site_annotator.dart' as callSiteAnnotator;
import '../transformations/lowering.dart' as lowering
show transformLibraries, transformProcedure;
import '../transformations/ffi.dart' as ffiHelper show importsFfi;
import '../transformations/ffi_definitions.dart' as transformFfiDefinitions
show transformLibraries;
import '../transformations/ffi_use_sites.dart' as transformFfiUseSites
@@ -153,17 +154,29 @@ class VmTarget extends Target {
this, coreTypes, hierarchy, libraries, referenceFromIndex);
logger?.call("Transformed mixin applications");
final ffiTransformerData = transformFfiDefinitions.transformLibraries(
component,
coreTypes,
hierarchy,
libraries,
diagnosticReporter,
referenceFromIndex,
changedStructureNotifier);
transformFfiUseSites.transformLibraries(component, coreTypes, hierarchy,
libraries, diagnosticReporter, ffiTransformerData, referenceFromIndex);
logger?.call("Transformed ffi annotations");
if (!ffiHelper.importsFfi(component, libraries)) {
logger?.call("Skipped ffi transformation");
} else {
// TODO(jensj/dacoharkes): We can probably limit the transformations to
// libraries that transitivley depend on dart:ffi.
final ffiTransformerData = transformFfiDefinitions.transformLibraries(
component,
coreTypes,
hierarchy,
libraries,
diagnosticReporter,
referenceFromIndex,
changedStructureNotifier);
transformFfiUseSites.transformLibraries(
component,
coreTypes,
hierarchy,
libraries,
diagnosticReporter,
ffiTransformerData,
referenceFromIndex);
logger?.call("Transformed ffi annotations");
}
// TODO(kmillikin): Make this run on a per-method basis.
bool productMode = environmentDefines["dart.vm.product"] == "true";
+14
View File
@@ -570,3 +570,17 @@ class FfiTransformerData {
FfiTransformerData(
this.replacedGetters, this.replacedSetters, this.emptyStructs);
}
/// Checks if any library depends on dart:ffi.
bool importsFfi(Component component, List<Library> libraries) {
Set<Library> allLibs = {...component.libraries, ...libraries};
final Uri dartFfiUri = Uri.parse("dart:ffi");
for (Library lib in allLibs) {
for (LibraryDependency dependency in lib.dependencies) {
if (dependency.targetLibrary.importUri == dartFfiUri) {
return true;
}
}
}
return false;
}