Open rakudrama opened 3 years ago
If I de-duplicate the 5.6M kernel AST InterfaceType
instances, there are about 100K unique instances.This is about 50x more instances that necessary. (instances.toSet().length
returns 102307)
@jensjoha could the Kernal AST reader be configured to intern types?
First thoughts:
Reference className
--- I'm not sure why it's non-final (update: making it final only seems to give errors in mixin_deduplication.dart
in pkg/vm
)).To answer the direct question: No, it's not currently possible to do that. It could be easily added though --- I guess we could start by doing it as an experiment?
/cc @johnniwinther --- thoughts on this?
Storage for an interning table is worthwhile:
The InterfaceType
objects is 32 bytes (4 words). Some instances share a const <DartType>[]
for the typeArguments
, but other instances 'own' an empty fixed-length _List
, for another 32 bytes.
A LinkedHashMap
has worst-case size of 6 words (x8 bytes) per entry + a small constant.
Best case storage today, assuming fully shared typeArguments
, is 325.6M = ~180MB
Worst case storage with interning map is (103K (32+48+32)) = ~11.5MB, or 6% of above.
I think we should try to make InterfaceType
immutable. This is how generally use it. I'll look into the mixin deduplication issue.
In the final phase of a modular dart2js compile of a large ACX app there are 5.6M Kernel
ir.InterfaceType
objects. Total size is 172.7MB, (retained 264MB).It seems like the 798k instances for
String
should be replaced by at most four instances for the different Nullability values (nullability is stored on the instance).A similar pattern occurs with the dart2js DartType version - many occurrences of some basic types.
I suspect that DartTypes are serialized structurally.