From 19ec2bb5866f074d8ca9e1c12da44689eae3f701 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Fri, 20 Mar 2015 12:14:30 +0700 Subject: [PATCH] compiler: improve `poset_from_mtypes` used for type coloring. Instead of doing the full matrix mtypes X cast_types, a grouping is done by the base classes of the types so that we compare only types whose base classes are in inheritance. For nitc/nitc/nitc the result is not that bad: before: 0m6.584s 17.605 GIr time passed in poset_from_mtypes: 26.01% (4.579 GIr) now: 0m5.880s (-10%) 15.088 GIr (-14%) time passed in poset_from_mtypes: 11.72% (1.768 GIr) In the best condition, I can now expect to compile in less than 6s. Note that coloring is still a MAJOR issue in term of compile time since 1/4 of the Ir are used to compute coloration. * type_coloring: 17.23% * property_coloring: 9.35% Signed-off-by: Jean Privat --- src/compiler/separate_compiler.nit | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/compiler/separate_compiler.nit b/src/compiler/separate_compiler.nit index f62d733..441abe1 100644 --- a/src/compiler/separate_compiler.nit +++ b/src/compiler/separate_compiler.nit @@ -478,13 +478,35 @@ class SeparateCompiler private fun poset_from_mtypes(mtypes, cast_types: Set[MType]): POSet[MType] do var poset = new POSet[MType] + + # Instead of doing the full matrix mtypes X cast_types, + # a grouping is done by the base classes of the type so + # that we compare only types whose base classes are in inheritance. + + var mtypes_by_class = new MultiHashMap[MClass, MType] for e in mtypes do + var c = e.as_notnullable.as(MClassType).mclass + mtypes_by_class[c].add(e) + poset.add_node(e) + end + + var casttypes_by_class = new MultiHashMap[MClass, MType] + for e in cast_types do + var c = e.as_notnullable.as(MClassType).mclass + casttypes_by_class[c].add(e) poset.add_node(e) - for o in cast_types do - if e == o then continue - poset.add_node(o) - if e.is_subtype(mainmodule, null, o) then - poset.add_edge(e, o) + end + + for c1, ts1 in mtypes_by_class do + for c2 in c1.in_hierarchy(mainmodule).greaters do + var ts2 = casttypes_by_class[c2] + for e in ts1 do + for o in ts2 do + if e == o then continue + if e.is_subtype(mainmodule, null, o) then + poset.add_edge(e, o) + end + end end end end -- 1.7.9.5