@@ -812,32 +812,38 @@ pub struct CtxtInterners<'tcx> {
812
812
813
813
impl < ' tcx > CtxtInterners < ' tcx > {
814
814
fn new ( arena : & ' tcx WorkerLocal < Arena < ' tcx > > ) -> CtxtInterners < ' tcx > {
815
+ // Default interner size - this value has been chosen empirically, and may need to be adjusted
816
+ // as the compiler evolves.
817
+ const N : usize = 2048 ;
815
818
CtxtInterners {
816
819
arena,
817
- type_ : Default :: default ( ) ,
818
- const_lists : Default :: default ( ) ,
819
- args : Default :: default ( ) ,
820
- type_lists : Default :: default ( ) ,
821
- region : Default :: default ( ) ,
822
- poly_existential_predicates : Default :: default ( ) ,
823
- canonical_var_infos : Default :: default ( ) ,
824
- predicate : Default :: default ( ) ,
825
- clauses : Default :: default ( ) ,
826
- projs : Default :: default ( ) ,
827
- place_elems : Default :: default ( ) ,
828
- const_ : Default :: default ( ) ,
829
- pat : Default :: default ( ) ,
830
- const_allocation : Default :: default ( ) ,
831
- bound_variable_kinds : Default :: default ( ) ,
832
- layout : Default :: default ( ) ,
833
- adt_def : Default :: default ( ) ,
834
- external_constraints : Default :: default ( ) ,
835
- predefined_opaques_in_body : Default :: default ( ) ,
836
- fields : Default :: default ( ) ,
837
- local_def_ids : Default :: default ( ) ,
838
- captures : Default :: default ( ) ,
839
- offset_of : Default :: default ( ) ,
840
- valtree : Default :: default ( ) ,
820
+ // The factors have been chosen by @FractalFir based on observed interner sizes, and local perf runs.
821
+ // To get the interner sizes, insert `eprintln` printing the size of the interner in functions like `intern_ty`.
822
+ // Bigger benchmarks tend to give more accurate ratios, so use something like `x perf eprintln --includes cargo`.
823
+ type_ : InternedSet :: with_capacity ( N * 16 ) ,
824
+ const_lists : InternedSet :: with_capacity ( N * 4 ) ,
825
+ args : InternedSet :: with_capacity ( N * 4 ) ,
826
+ type_lists : InternedSet :: with_capacity ( N * 4 ) ,
827
+ region : InternedSet :: with_capacity ( N * 4 ) ,
828
+ poly_existential_predicates : InternedSet :: with_capacity ( N / 4 ) ,
829
+ canonical_var_infos : InternedSet :: with_capacity ( N / 2 ) ,
830
+ predicate : InternedSet :: with_capacity ( N ) ,
831
+ clauses : InternedSet :: with_capacity ( N ) ,
832
+ projs : InternedSet :: with_capacity ( N * 4 ) ,
833
+ place_elems : InternedSet :: with_capacity ( N * 2 ) ,
834
+ const_ : InternedSet :: with_capacity ( N * 2 ) ,
835
+ pat : InternedSet :: with_capacity ( N ) ,
836
+ const_allocation : InternedSet :: with_capacity ( N ) ,
837
+ bound_variable_kinds : InternedSet :: with_capacity ( N * 2 ) ,
838
+ layout : InternedSet :: with_capacity ( N ) ,
839
+ adt_def : InternedSet :: with_capacity ( N ) ,
840
+ external_constraints : InternedSet :: with_capacity ( N ) ,
841
+ predefined_opaques_in_body : InternedSet :: with_capacity ( N ) ,
842
+ fields : InternedSet :: with_capacity ( N * 4 ) ,
843
+ local_def_ids : InternedSet :: with_capacity ( N ) ,
844
+ captures : InternedSet :: with_capacity ( N ) ,
845
+ offset_of : InternedSet :: with_capacity ( N ) ,
846
+ valtree : InternedSet :: with_capacity ( N ) ,
841
847
}
842
848
}
843
849
0 commit comments