[m-rev.] for review: Assign mmake .classes variable conditionally.

Peter Wang novalazy at gmail.com
Tue Jan 31 15:47:00 AEDT 2023


Evaluating the .classes variable in a Mmakefile can be quite slow.
We can speed up mmake invocations by assigning the variable to an
empty value unless we are targeting Java.

On my machine, a call to mmake in an up-to-date compiler directory
now takes about 0.4 seconds, down from 1.2 seconds.

compiler/write_deps_file.m:
    As above.

diff --git a/compiler/write_deps_file.m b/compiler/write_deps_file.m
index 0c9f32006..eaf81ea6e 100644
--- a/compiler/write_deps_file.m
+++ b/compiler/write_deps_file.m
@@ -1567,12 +1567,20 @@ generate_dv_file(Globals, SourceFileName, ModuleName, DepsMap,
     % `module\$*.class', hence the "\\$$*.class" below.
     % If no such files exist, Make will use the pattern verbatim,
     % so we enclose the pattern in a `wildcard' function to prevent this.
-    MmakeVarClasses = mmake_var_defn_list(ModuleMakeVarName ++ ".classes",
+    % Evaluating the .classes variable can be slow so we make it conditional
+    % on the grade.
+    MmakeVarClassesJava = mmake_var_defn_list(ModuleMakeVarName ++ ".classes",
         [string.format("$(%s.mods:%%=$(classes_subdir)%%.class)",
             [s(ModuleMakeVarName)]),
         string.format(
             "$(wildcard $(%s.mods:%%=$(classes_subdir)%%\\$$*.class))",
             [s(ModuleMakeVarName)])]),
+    MmakeVarClassesNonJava = mmake_var_defn(ModuleMakeVarName ++ ".classes",
+        ""),
+    MmakeFragmentVarClasses = mmf_conditional_entry(
+        mmake_cond_grade_has_component("java"),
+        MmakeVarClassesJava, MmakeVarClassesNonJava),
+
     MmakeVarCss = mmake_var_defn(ModuleMakeVarName ++ ".css",
         string.format("$(%s.mods:%%=$(css_subdir)%%.cs)",
             [s(ModuleMakeVarName)])),
@@ -1710,7 +1718,8 @@ generate_dv_file(Globals, SourceFileName, ModuleName, DepsMap,
         string.format("$(%s.mods:%%=%%.prof)",
             [s(ModuleMakeVarName)])),
 
-    MmakeEntries =
+    MmakeFragmentsA =
+        list.map(mmake_entry_to_fragment,
             [MmakeStartComment, MmakeVarModuleMs,
             MmakeVarModuleDepErrs, MmakeVarModuleErrs,
             MmakeVarModuleMods, MmakeVarModuleParentMods,
@@ -1718,8 +1727,10 @@ generate_dv_file(Globals, SourceFileName, ModuleName, DepsMap,
             MmakeVarInitCs, MmakeVarAllCs, MmakeVarCs, MmakeVarDlls,
             MmakeVarAllOs, MmakeVarAllPicOs, MmakeVarOs, MmakeVarPicOs,
             MmakeVarUseds,
-        MmakeVarJavas, MmakeVarAllJavas, MmakeVarClasses,
-        MmakeVarCss, MmakeVarAllCss,
+            MmakeVarJavas, MmakeVarAllJavas]),
+    MmakeFragmentsB =
+        list.map(mmake_entry_to_fragment,
+            [MmakeVarCss, MmakeVarAllCss,
             MmakeVarDirs, MmakeVarDirOs,
             MmakeVarDates, MmakeVarDate0s, MmakeVarDate3s,
             MmakeVarOptDates, MmakeVarTransOptDates,
@@ -1728,9 +1739,11 @@ generate_dv_file(Globals, SourceFileName, ModuleName, DepsMap,
             MmakeVarMhs, MmakeVarAllMihs, MmakeVarAllMhs,
             MmakeVarInts, MmakeVarInt0s, MmakeVarAllInt0s, MmakeVarInt3s,
             MmakeVarOpts, MmakeVarTransOpts,
-        MmakeVarAnalysiss, MmakeVarRequests, MmakeVarImdgs, MmakeVarProfs],
-    MmakeFile = cord.from_list(
-        list.map(mmake_entry_to_fragment, MmakeEntries)).
+            MmakeVarAnalysiss, MmakeVarRequests, MmakeVarImdgs, MmakeVarProfs]),
+    MmakeFile =
+        cord.from_list(MmakeFragmentsA) ++
+        cord.singleton(MmakeFragmentVarClasses) ++
+        cord.from_list(MmakeFragmentsB).
 
 %---------------------%
 
-- 
2.39.0



More information about the reviews mailing list