[kernel] Optimize computeThisFunctionType

When compiling compile.dart:
148,192 FunctionType are created via `computeThisFunctionType`.
133,085 of them have no named parameters; 141,507 of them have no type
parameters; 128,357 of them have neither.

This CL makes it not create new lists when not needed
(or create empty iterators and sort empty lists), and makes the lists
it do create not growable.

Change-Id: Ibd5fef458b8a1254aa2f1fab80d0449a2f0bfd94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298541
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Jens Johansen 2023-04-26 11:29:28 +00:00 committed by Commit Queue
parent 6f1b754a2f
commit 43b499cf9a

View file

@ -4153,15 +4153,27 @@ class FunctionNode extends TreeNode {
/// [FunctionType.withoutTypeParameters].
FunctionType computeThisFunctionType(Nullability nullability) {
TreeNode? parent = this.parent;
List<NamedType> named =
namedParameters.map(_getNamedTypeOfVariable).toList(growable: false);
named.sort();
// We need create a copy of the list of type parameters, otherwise
// transformations like erasure don't work.
List<TypeParameter> typeParametersCopy = new List<TypeParameter>.of(
parent is Constructor
? parent.enclosingClass.typeParameters
: typeParameters);
List<NamedType> named;
if (namedParameters.isEmpty) {
named = const <NamedType>[];
} else {
named =
namedParameters.map(_getNamedTypeOfVariable).toList(growable: false);
named.sort();
}
List<TypeParameter> typeParametersCopy;
List<TypeParameter> typeParametersToCopy = parent is Constructor
? parent.enclosingClass.typeParameters
: typeParameters;
if (typeParametersToCopy.isEmpty) {
typeParametersCopy = const <TypeParameter>[];
} else {
// We need create a copy of the list of type parameters, otherwise
// transformations like erasure don't work.
typeParametersCopy =
new List<TypeParameter>.of(typeParametersToCopy, growable: false);
}
return new FunctionType(
positionalParameters.map(_getTypeOfVariable).toList(growable: false),
returnType,