<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Code optimization</title><link>https://sourceforge.net/p/ats-lang/wiki/Code%2520optimization/</link><description>Recent changes to Code optimization</description><atom:link href="https://sourceforge.net/p/ats-lang/wiki/Code%20optimization/feed" rel="self"/><language>en</language><lastBuildDate>Sun, 28 Apr 2013 13:33:32 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/ats-lang/wiki/Code%20optimization/feed" rel="self" type="application/rss+xml"/><item><title>Code optimization modified by Brandon Barker</title><link>https://sourceforge.net/p/ats-lang/wiki/Code%2520optimization/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v7
+++ v8
@@ -6,8 +6,10 @@

  - Making use of the knowledge that separate val declarations within the same scope technically denote different vals on the stack should not preclude one from using a natural style. For instance:

+~~~~~~~~~~~~~~~
     val x = 5
     val x = 7
+~~~~~~~~~~~~~~~

 here no extra space is allocated for the second 'x' due to constant propagation. It is in generally unlikely that such a coding style would incur any penalty.

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brandon Barker</dc:creator><pubDate>Sun, 28 Apr 2013 13:33:32 -0000</pubDate><guid>https://sourceforge.net4f844fa45387ee64d9d0809fbff024c83edcb9f5</guid></item><item><title>Code optimization modified by Brandon Barker</title><link>https://sourceforge.net/p/ats-lang/wiki/Code%2520optimization/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v6
+++ v7
@@ -3,6 +3,13 @@
 - A `macdef` in ATS cannot involve types (but it can in ATS2); use macros only in cases where using functions would be inconvenient. [Using macros probably does not make your code run more quickly][1], since `gcc -O2` already inlines functions somewhat aggressively.

   [1]: https://groups.google.com/d/msg/ats-lang-users/Ql64LA9Wi88/fwrR7kJ3Ww0J
+
+ - Making use of the knowledge that separate val declarations within the same scope technically denote different vals on the stack should not preclude one from using a natural style. For instance:
+
+    val x = 5
+    val x = 7
+
+here no extra space is allocated for the second 'x' due to constant propagation. It is in generally unlikely that such a coding style would incur any penalty.

 ## Optimization tips ##

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brandon Barker</dc:creator><pubDate>Sun, 28 Apr 2013 13:32:32 -0000</pubDate><guid>https://sourceforge.netdad404dab29f0f909c0a59e98d7e2acdae6f4afe</guid></item><item><title>Code optimization modified by Brandon Barker</title><link>https://sourceforge.net/p/ats-lang/wiki/Code%2520optimization/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v5
+++ v6
@@ -6,7 +6,7 @@

 ## Optimization tips ##

-  - Instead of freeing an instance of a linear type and immediately creating and returning a new one with the same value in a case expression, like this
+- Instead of freeing an instance of a linear type and immediately creating and returning a new one with the same value in a case expression, like this

         case+ x of
         | ~GRgenes (genes) =&gt; GRgenes (genes)
@@ -17,3 +17,9 @@
         | GRgenes _ =&gt; (fold@ x; x)

     because `@fold` is compiled into a "noop".
+
+
+
+- Remove anonymous closure definitions from function calls when possible, to avoid having them created each time the loop is called. For instance, a simple string comparison function can be created like so:
+
+        val cmp_str = lam(x:string,y:string):int = compare (x, y)
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brandon Barker</dc:creator><pubDate>Sun, 28 Apr 2013 05:18:01 -0000</pubDate><guid>https://sourceforge.net8b881b65fb42001e8f4af38ab3e96161e04eb5ee</guid></item><item><title>WikiPage Code optimization modified by jeffrey</title><link>https://sourceforge.net/p/ats-lang/wiki/Code%2520optimization/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v4
+++ v5
@@ -1,29 +1,19 @@
-When not to attempt clever code optimization. 
-----------------------------------------------
+## When not to attempt clever code optimization ##

-**macdef**
-A macdef in ATS cannot involve types (but it can in ATS2); in ATS, use macros only in cases where using functions would be inconvenient. As gcc (with -O2) does inlining
-pretty aggressively, using macros so as to gain efficiency is rarely needed if at all ([source](https://groups.google.com/d/msg/ats-lang-users/Ql64LA9Wi88/fwrR7kJ3Ww0J)).
+- A `macdef` in ATS cannot involve types (but it can in ATS2); use macros only in cases where using functions would be inconvenient. [Using macros probably does not make your code run more quickly][1], since `gcc -O2` already inlines functions somewhat aggressively.

+  [1]: https://groups.google.com/d/msg/ats-lang-users/Ql64LA9Wi88/fwrR7kJ3Ww0J

+## Optimization tips ##

+  - Instead of freeing an instance of a linear type and immediately creating and returning a new one with the same value in a case expression, like this

-Optimization Tips.
-----------------------------------------------
+        case+ x of
+        | ~GRgenes (genes) =&gt; GRgenes (genes)

-**Returning a matched linear value in a case expression**
+    do this

-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-case+ x of
-| ~GRgenes (genes) =&gt; GRgenes (genes)
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        case+ x of
+        | GRgenes _ =&gt; (fold@ x; x)

-
-This means that you free a node and then create another node that is just the same as the one freed.
-
-A more efficient way to do this would be:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-case+ x of
-| GRgenes _ =&gt; (fold@ x; x) // fold@ is compiled into a no-op.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    because `@fold` is compiled into a "noop".
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jeffrey</dc:creator><pubDate>Thu, 14 Mar 2013 22:39:35 -0000</pubDate><guid>https://sourceforge.netf55549dc5458badd63520840d22e5fb2f2ee4202</guid></item><item><title>WikiPage Code Optimization modified by Brandon Barker</title><link>https://sourceforge.net/p/ats-lang/wiki/Code%2520Optimization/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v3
+++ v4
@@ -8,7 +8,7 @@

-Optimization Tips
+Optimization Tips.
 ----------------------------------------------

 **Returning a matched linear value in a case expression**
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brandon Barker</dc:creator><pubDate>Thu, 14 Mar 2013 02:55:11 -0000</pubDate><guid>https://sourceforge.netea118ab5e3ec0c615fae45dccdff2fb67ee0edfd</guid></item><item><title>WikiPage Code Optimization modified by Brandon Barker</title><link>https://sourceforge.net/p/ats-lang/wiki/Code%2520Optimization/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v2
+++ v3
@@ -1,3 +1,29 @@
-**When not to attempt clever code optimization. **
+When not to attempt clever code optimization. 
+----------------------------------------------
+
+**macdef**
 A macdef in ATS cannot involve types (but it can in ATS2); in ATS, use macros only in cases where using functions would be inconvenient. As gcc (with -O2) does inlining
 pretty aggressively, using macros so as to gain efficiency is rarely needed if at all ([source](https://groups.google.com/d/msg/ats-lang-users/Ql64LA9Wi88/fwrR7kJ3Ww0J)).
+
+
+
+
+Optimization Tips
+----------------------------------------------
+
+**Returning a matched linear value in a case expression**
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+case+ x of
+| ~GRgenes (genes) =&gt; GRgenes (genes)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+This means that you free a node and then create another node that is just the same as the one freed.
+
+A more efficient way to do this would be:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+case+ x of
+| GRgenes _ =&gt; (fold@ x; x) // fold@ is compiled into a no-op.
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brandon Barker</dc:creator><pubDate>Thu, 14 Mar 2013 02:52:11 -0000</pubDate><guid>https://sourceforge.net177ebf751dcf819b5b993e7776facd25ac1be5b8</guid></item><item><title>WikiPage Code Optimization modified by Brandon Barker</title><link>https://sourceforge.net/p/ats-lang/wiki/Code%2520Optimization/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -1,4 +1,3 @@
-
 **When not to attempt clever code optimization. **
 A macdef in ATS cannot involve types (but it can in ATS2); in ATS, use macros only in cases where using functions would be inconvenient. As gcc (with -O2) does inlining
-pretty aggressively, using macros so as to gain efficiency is rarely needed if at all.
+pretty aggressively, using macros so as to gain efficiency is rarely needed if at all ([source](https://groups.google.com/d/msg/ats-lang-users/Ql64LA9Wi88/fwrR7kJ3Ww0J)).
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brandon Barker</dc:creator><pubDate>Wed, 13 Mar 2013 21:41:16 -0000</pubDate><guid>https://sourceforge.netc023fad9036afd8a43bfa0fac13c344748a14028</guid></item><item><title>WikiPage Code Optimization modified by Brandon Barker</title><link>https://sourceforge.net/p/ats-lang/wiki/Code%2520Optimization/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;strong&gt;When not to attempt clever code optimization. &lt;/strong&gt;&lt;br /&gt;
A macdef in ATS cannot involve types (but it can in ATS2); in ATS, use macros only in cases where using functions would be inconvenient. As gcc (with -O2) does inlining&lt;br /&gt;
pretty aggressively, using macros so as to gain efficiency is rarely needed if at all.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brandon Barker</dc:creator><pubDate>Wed, 13 Mar 2013 21:35:10 -0000</pubDate><guid>https://sourceforge.net676c93b3e56e78bcb2434a33da5ab33d54692260</guid></item></channel></rss>