[m-rev.] a tale of three attempted optimizations

Zoltan Somogyi zoltan.somogyi at runbox.com
Fri Jun 7 10:26:15 AEST 2024


When I looked into github issue #131, I found three new opportunities
to optimize for very large code, such as the oil module in that issue.
The three Log/DIFF pairs report the resulting diffs. The OIL_TIMES_SUMMARY
reports benchmarks results on the compiler compiling oil.m, for a base
version without any changes, and three versions each containing only
one of the three diffs. The SPEEDSUM file reports benchmark results
on tools/speedtest for the same four versions, minus one (see below).

The change to const_struct.m is the simplest: the deletion of an unused
field. It yields a speedup of about 2.6% when compiling oil.m, and has
no effect on tools/speedtest. (It does get a speedup, but it is in the noise.)
I have committed it.

The change to polymorphism_goal.m looks reasonably straightforward as well:
leave the goals in a from_ground_term scope untouched if the type of the term
that the scope represents guarantees that no changes can be needed. However
the effect of this diff on compilation time on the oil program is very strange.
The STATS files show that the this optimization, as intended, reduces the time taken
by the polymorphism pass from just below one second to almost nothing.
However, the overall result is NOT a one-second speedup, but a one-second slowdown.
The STATS files come from single executions, but the OIL_TIMES_SUMMARY file
shows the same effect, and it is derived from ten executions of each version.
Does anyone have any idea of what could possibly be causing this slowdown?
I tried several variations of the attached diff, and they all had the same problem.

I didn't even try to benchmark this change with tools/speedtest, because
(a) in the compiler, as in most programs, most from_ground_term scopes
contain only a few goals, and (b) for such scopes, the cost of testing the type
would probably be comparable with, or even larger than, the cost of testing
the few unifications of those scopes. The effect would be small enough
not to be noticeable, but there is no point to it if it buys us nothing on
larger programs.

The third change is also intended to optimize away unnecessary work,
this time in the bookkeeping needed for the detection of occur check violations.
The diff gets an impressive 10% speedup for compiling oil.m, but suffers
a 5% or so slowdown on tools/speedtest. In this case, the cause is almost certainly
the extra argument passing needed. This is worthwhile when it prevents a huge
amount of unnecessary work, but it seems that most workloads don't lead to
much unnecessary work, so the downside of this "optimization" is greater
than its upside. I therefore only want to get this diff into the record, i.e.
into the m-rev archive. I don't intend to commit it, though I do intend to add
a comment explaining this attempt.

Zoltan.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Log.cs
Type: application/octet-stream
Size: 122 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20240607/588cb614/attachment-0008.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DIFF.cs
Type: application/octet-stream
Size: 3778 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20240607/588cb614/attachment-0009.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Log.pg
Type: application/octet-stream
Size: 1050 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20240607/588cb614/attachment-0010.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DIFF.pg
Type: application/octet-stream
Size: 26942 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20240607/588cb614/attachment-0011.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Log.sh
Type: text/x-sh
Size: 1108 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20240607/588cb614/attachment-0002.sh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DIFF.sh
Type: text/x-sh
Size: 23098 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20240607/588cb614/attachment-0003.sh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OIL_TIMES_SUMMARY
Type: application/octet-stream
Size: 330 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20240607/588cb614/attachment-0012.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SPEEDSUM.oil.2024_06_06
Type: application/octet-stream
Size: 210 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20240607/588cb614/attachment-0013.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: STATS.base
Type: application/octet-stream
Size: 8608 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20240607/588cb614/attachment-0014.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: STATS.polymorphism_goal
Type: application/octet-stream
Size: 8602 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20240607/588cb614/attachment-0015.obj>


More information about the reviews mailing list