<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2015-07-26 23:06 GMT+02:00 Joachim Breitner <span dir="ltr"><<a href="mailto:mail@joachim-breitner.de" target="_blank">mail@joachim-breitner.de</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<span class=""><br>
Am Sonntag, den 26.07.2015, 22:50 +0200 schrieb Lennart Kolmodin:<br>
> This trick relies so much on that the user's code has been inlined<br>
> properly that it probably very rarely fires in a real application. It<br>
> does wonders in the unrealistic micro benchmark, though :)<br>
<br>
</span>what is the name of the rule? Can you find it on this list:<br>
<a href="https://gist.github.com/nomeata/071c1f87450cf668bbeb" rel="noreferrer" target="_blank">https://gist.github.com/nomeata/071c1f87450cf668bbeb</a></blockquote><div><br></div>The rules;<br><div><div><font face="monospace, monospace">{-# RULES</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">"<$> to <*>" forall f g.</font></div><div><font face="monospace, monospace">  (<$>) f g = returnG f <*> g</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">"readN/readN merge" forall n m f g.</font></div><div><font face="monospace, monospace">  apG (readN n f) (readN m g) = readN (n+m) (\bs -> f bs $ g (B.unsafeDrop n bs))</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">"returnG/readN swap" [~1] forall f.</font></div><div><font face="monospace, monospace">  returnG f = readN 0 (const f)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">"readN 0/returnG swapback" [1] forall f.</font></div><div><font face="monospace, monospace">  readN 0 f = returnG (f B.empty) #-}</font></div></div><div><br></div><div>From your list (all of stackage with -ddump-rule-firings? brilliant! :));</div><div><font face="monospace, monospace"><span style="color:rgb(51,51,51);font-size:12px;line-height:16.7999992370605px;white-space:pre">    399 Rule fired: <$> to <*></span><br></font></div><div><font face="monospace, monospace"><span style="color:rgb(51,51,51);font-size:12px;line-height:16.7999992370605px;white-space:pre">    106 Rule fired: readN/readN merge</span><span style="color:rgb(51,51,51);font-size:12px;line-height:16.7999992370605px;white-space:pre"><br></span></font></div><div><font face="monospace, monospace"><span style="color:rgb(51,51,51);font-size:12px;line-height:16.7999992370605px;white-space:pre">   1373 Rule fired: returnG/readN swap</span><span style="color:rgb(51,51,51);font-size:12px;line-height:16.7999992370605px;white-space:pre"><br></span></font></div><div><span style="color:rgb(51,51,51);font-size:12px;line-height:16.7999992370605px;white-space:pre"><font face="monospace, monospace">   2351 Rule fired: readN 0/returnG swapback</font></span><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16.7999992370605px;white-space:pre"><br></span></div><div><br></div><div>The "<font face="monospace, monospace">readN/readN merge</font>" rule is what gives the speedup, the other rules are needed just to get the code lined up for the merge rule to fire.</div><div>So it fired 106 times. That's not a lot. When compiling one of the binary benchmarks it fires 33 times.</div><div>It might fire less often than it could, because the "<span style="font-family:monospace,monospace"><$> to <*>" </span>rule might not get to fire as often as it wants (just like the warning says).</div><div>But, I can't slap a INLINE or NOINLINE on <$> though, since it's not part of the binary library.</div><div>So even if it does fire for some program out there, I'm still inclined to remove the rules. It's a little bit too much black magic.</div><div><br></div><div>Lennart</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
Greetings,<br>
Joachim<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Joachim “nomeata” Breitner<br>
  <a href="mailto:mail@joachim-breitner.de">mail@joachim-breitner.de</a> • <a href="http://www.joachim-breitner.de/" rel="noreferrer" target="_blank">http://www.joachim-breitner.de/</a><br>
  Jabber: <a href="mailto:nomeata@joachim-breitner.de">nomeata@joachim-breitner.de</a>  • GPG-Key: 0xF0FBF51F<br>
  Debian Developer: <a href="mailto:nomeata@debian.org">nomeata@debian.org</a><br>
</font></span></blockquote></div><br></div></div>