Skip to content

Commit a59a2b1

Browse files
Markzipandart-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[ddc] Cache the library identifier used in interface type recipes
`interfaceTypeRecipe` uses `p.withoutExtension` and `pathToJSIdentifier`, which iterate on the entire string and are mostly redundant. Adding this cache cuts compile time for heavy mixin libraries about 30%. See related bug: flutter/flutter#190436 Change-Id: Iaef6d398d0a8807221c50cbaa733ed9c7b9e7dd0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/553180 Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Mark Zhou <[email protected]>
1 parent e3a317e commit a59a2b1

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎pkg/dev_compiler/lib/src/kernel/type_recipe_generator.dart‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class _TypeRecipeVisitor extends DartTypeVisitor<String>
306306
/// All of the [InterfaceType]s visited.
307307
final _visitedInterfaceTypes = <InterfaceType>{};
308308
final _visitedJsInteropTypes = <InterfaceType>{};
309+
310+
/// Maps a [Library] to the identifier name used in its type recipe.
311+
final _libraryRecipeNames = <Library, String>{};
309312
final CoreTypes _coreTypes;
310313

311314
_TypeRecipeVisitor(this._typeEnvironment, this._coreTypes);
@@ -569,8 +572,10 @@ class _TypeRecipeVisitor extends DartTypeVisitor<String>
569572

570573
/// Returns the recipe for the interface type introduced by [cls].
571574
String interfaceTypeRecipe(Class cls) {
572-
var path = p.withoutExtension(cls.enclosingLibrary.importUri.path);
573-
var library = pathToJSIdentifier(path);
575+
var enclosingLibrary = cls.enclosingLibrary;
576+
var library = _libraryRecipeNames[enclosingLibrary] ??= pathToJSIdentifier(
577+
p.withoutExtension(enclosingLibrary.importUri.path),
578+
);
574579
return '$library${Recipe.librarySeparatorString}${cls.name}';
575580
}
576581

0 commit comments

Comments
 (0)