[m-dev.] diff: minor performance improvement in modes.m

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Feb 25 05:35:55 AEDT 2000


I spent a bit of time trying to speed up mode analysis,
mostly without much luck.  Anyway, here's the best I have
so far.

----------

Estimated hours taken: 12

Improve the performance of mode analysis on modules containing large terms,
e.g. samples/eliza.m, for which it currently performs badly.
This change speeds up compilation of samples/eliza.m by about 15%,
while the speed of compilation for compiler/[a-d]*.m and compiler/options.m
remains pretty much unaffected (the slowdown, if any, is less than 1%).

compiler/modes.m:
	Ensure that we insert the live_vars sets in reverse order,
	so that when we come to removing them (using list__delete_first),
	in the typical case where no delaying is involved
	the one we want to remove will be at the front of the list.

Workspace: /d-drive/home/hg/fjh/mercury
Index: compiler/modes.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.238
diff -u -d -r1.238 modes.m
--- compiler/modes.m	2000/01/26 02:04:26	1.238
+++ compiler/modes.m	2000/02/24 18:32:44
@@ -1416,9 +1416,16 @@
 
 mode_info_add_goals_live_vars([]) --> [].
 mode_info_add_goals_live_vars([Goal | Goals]) -->
+	% We add the live vars for the goals in the goal list
+	% in reverse order, because this ensures that in the
+	% common case (where there is no delaying), when we come
+	% to remove the live vars for the first goal
+	% they will have been added last and will thus be
+	% at the start of the list of live vars sets, which
+	% makes them cheaper to remove.
+	mode_info_add_goals_live_vars(Goals),
 	{ goal_get_nonlocals(Goal, Vars) },
-	mode_info_add_live_vars(Vars),
-	mode_info_add_goals_live_vars(Goals).
+	mode_info_add_live_vars(Vars).
 
 mode_info_remove_goals_live_vars([]) --> [].
 mode_info_remove_goals_live_vars([Goal | Goals]) -->

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list