<rss xmlns:dc="http://purl.org/dc/elements/1.1" version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>haXe Blog</title><link>http://blog.haxe.org</link><description>News from the haXe Community</description><generator>hxBlog</generator><language></language><item><title>Strands™ Summer 2008 haXe Project Announcement</title><link>http://blog.haxe.org/entry/34</link><guid>http://blog.haxe.org/entry/34</guid><dc:date>2008-04-29 18:36:29</dc:date><pubDate>2008-04-29 18:36:29</pubDate><dc:creator>Franco Ponticelli</dc:creator><author>Franco Ponticelli</author><description>&lt;p&gt;We are pleased to announce that &lt;a href="http://www.strands.com/"&gt;Strands.com&lt;/a&gt;, a provider of social recommendation technologies, is hosting a student open source coding summer project, focused solely on haXe.&lt;/p&gt;  &lt;p&gt;You can find more informat [...]</description><content:encoded>&lt;p&gt;We are pleased to announce that &lt;a href="http://www.strands.com/"&gt;Strands.com&lt;/a&gt;, a provider of social recommendation technologies, is hosting a student open source coding summer project, focused solely on haXe.&lt;/p&gt;

&lt;p&gt;You can find more information on the project and how to participate on this announcement page:
&lt;a href="http://labs.strands.com/Summer2008HaxeProject/"&gt;http://labs.strands.com/Summer2008HaxeProject/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This project has very similar funding and terms to the 'other' open source summer coding project that you may be aware of.  However, it is designed solely for current students in the haXe community.&lt;/p&gt;

&lt;p&gt;Strands.com will provide funding for not more than 3 students, for not more than 2 projects.  To see a list of suggested projects, please see the announcement page.  We will prioritize the listed projects as well as those that get the most student interest.&lt;/p&gt;

&lt;p&gt;Currently, the project involves myself (a PhD candidate at the Indiana University School of Informatics), and Franco Ponticelli, notable haXe community member and co-author of the &lt;a href="http://www.amazon.com/dp/0470122137?tag=buildlabcom-20&amp;camp=14573&amp;creative=327641&amp;linkCode=as1&amp;creativeASIN=0470122137&amp;adid=0YDQV1KCHEKN0AW8VCYW&amp;"&gt;recent book on haXe&lt;/a&gt;.  We look forward to making this summer the "Summer of haXe"!&lt;/p&gt;

&lt;p&gt;If you have any questions about the project, please use this mailing list.&lt;/p&gt;

&lt;p&gt;Best,&lt;/p&gt;

&lt;p&gt;- &lt;em&gt;Justin and Franco&lt;/em&gt;&lt;/p&gt;</content:encoded></item><item><title>Physaxe : haXe Physics Engine</title><link>http://blog.haxe.org/entry/33</link><guid>http://blog.haxe.org/entry/33</guid><dc:date>2008-04-06 19:18:04</dc:date><pubDate>2008-04-06 19:18:04</pubDate><dc:creator>Nicolas Cannasse</dc:creator><author>Nicolas Cannasse</author><description>I'm please to announce the 1.0 Release of Physaxe : a haXe 2D Rigid Body Physics Engine heavily optimized for Flash Player 9.  A demo is always better than words, so you can play the following SWF, **use 1-8 keys to change the demo** and **click** to [...]</description><content:encoded>
&lt;p&gt;I'm please to announce the 1.0 Release of Physaxe&amp;nbsp;: a haXe 2D Rigid Body Physics Engine heavily optimized for Flash Player 9.&lt;/p&gt;
&lt;p&gt;A demo is always better than words, so you can play the following SWF, &lt;strong&gt;use 1-8 keys to change the demo&lt;/strong&gt; and &lt;strong&gt;click&lt;/strong&gt; to fire a block&amp;nbsp;:&lt;/p&gt;


&lt;div id="phx_demo"&gt;&lt;/div&gt;
&lt;script type="text/javascript"&gt;
var so = new SWFObject("http://physaxe.googlecode.com/files/phxdemo.swf", "phx", "580", "450", "9", "#FFFFFF");
so.addParam("scale","exactfit");
so.write("phx_demo");
&lt;/script&gt;

&lt;p&gt;(if you want to check the real CPU spent by physaxe, you can press the 'D' key to disable drawing, which takes most of the CPU)&lt;/p&gt;
&lt;p&gt;See the Physaxe &lt;a href="http://code.google.com/p/physaxe"&gt;project page&lt;/a&gt; for more informations.&lt;/p&gt;
&lt;p&gt;Enjoy&amp;nbsp;!&lt;/p&gt;
&lt;p&gt;Nicolas&lt;/p&gt;

</content:encoded></item><item><title>Towards haXe 2.0</title><link>http://blog.haxe.org/entry/32</link><guid>http://blog.haxe.org/entry/32</guid><dc:date>2008-03-24 10:31:46</dc:date><pubDate>2008-03-24 10:31:46</pubDate><dc:creator>Nicolas Cannasse</dc:creator><author>Nicolas Cannasse</author><description>After 1.19 Release, I'm planning to roll up several changes in the language and its libraries, with some of them which might require some code changes. This is done in order to "cleanup" features and libraries that were added incrementally during the [...]</description><content:encoded>
&lt;p&gt;After 1.19 Release, I'm planning to roll up several changes in the language and its libraries, with some of them which might require some code changes. This is done in order to "cleanup" features and libraries that were added incrementally during the past 2 years of development and prepare the language for future additional platforms.&lt;/p&gt;
&lt;p&gt;All these changes can be discussed on the mailing list and you're welcome to submit your own there as well.&lt;/p&gt;
&lt;p&gt;The list of changes are available on the &lt;a href="http://haxe.org/proposals/haxe2"&gt;haXe Wiki&lt;/a&gt;.&lt;/p&gt;

</content:encoded></item><item><title>Flash 9 Optimizations</title><link>http://blog.haxe.org/entry/31</link><guid>http://blog.haxe.org/entry/31</guid><dc:date>2008-03-08 15:51:45</dc:date><pubDate>2008-03-08 15:51:45</pubDate><dc:creator>Nicolas Cannasse</dc:creator><author>Nicolas Cannasse</author><description>The new virtual machine than can run AS3 and haXe languages in the Flash Player 9 brings a lot of additional speed for many common operations. This is very good news for developers since you can now write more complex algorithms in Flash such as 3D o [...]</description><content:encoded>
&lt;p&gt;The new virtual machine than can run AS3 and haXe languages in the Flash Player 9 brings a lot of additional speed for many common operations. This is very good news for developers since you can now write more complex algorithms in Flash such as 3D or Physics engine with correct performances.&lt;/p&gt;
&lt;p&gt;However, there are still several pitfalls since some operations are pretty slow when compared to others&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;creating a new object is slow&lt;/strong&gt;&amp;nbsp;: if you have a lot of short living objects that are allocated frequently, it's better to create a "Allocator" class that will store a list of reusable instances.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;calling a lot of methods is not so fast&lt;/strong&gt;&amp;nbsp;: when you have some small methods that are very often called, it's often faster to rewrite the code directly in the calling method. For example, given a Point class&amp;nbsp;:
&lt;pre class="code haxe"&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; p = &lt;span class="keyword"&gt;new&lt;/span&gt; Point(4,5);
&lt;span class="comment"&gt;// the expression :&lt;/span&gt;
p.add(p2.x,p2.y);
&lt;span class="comment"&gt;// would be faster if written directly :&lt;/span&gt;
p.x += p2.x;
p.y += p2.y;
&lt;/pre&gt;
This process of replacing a method call with the actual code is called &lt;strong&gt;inlining&lt;/strong&gt;, and haXe compiler has support for an &lt;strong&gt;inline&lt;/strong&gt; keyword so that you can define which methods will be automatically inlined by the compiler when called (see &lt;a href="http://haxe.org/ref#inline"&gt;haXe Documentation&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;accessing static vars and functions is slow&lt;/strong&gt;&amp;nbsp;: you can either create an instance and use instance variables and methods instead of static ones or use the haXe &lt;strong&gt;inline&lt;/strong&gt; keyword.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;reading and writing into arrays is slow&lt;/strong&gt;&amp;nbsp;: this is very bad news. The only native data structure of Flash9 is painfully slow. It's a lot faster to access a typed instance field than to access an array. One way to optimize that is to create your own linked list&amp;nbsp;:
&lt;pre class="code haxe"&gt;
&lt;span class="comment"&gt;// a cell containing instances of MyClass&lt;/span&gt;
&lt;span class="keyword"&gt;class&lt;/span&gt; MyCell {
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;var&lt;/span&gt; elt : MyClass;
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;var&lt;/span&gt; next : MyCell;
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;function&lt;/span&gt; &lt;span class="keyword"&gt;new&lt;/span&gt;( elt, next ) {
        &lt;span class="keyword"&gt;this&lt;/span&gt;.elt = elt;
        &lt;span class="keyword"&gt;this&lt;/span&gt;.next = next;
    }
}
&lt;span class="comment"&gt;// a list managing a chained list of MyCell&lt;/span&gt;
&lt;span class="keyword"&gt;class&lt;/span&gt; MyList {
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;var&lt;/span&gt; head : MyCell;
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;function&lt;/span&gt; &lt;span class="keyword"&gt;new&lt;/span&gt;() {
        head = null;
    }
    &lt;span class="comment"&gt;// add an element at the beginning of the list &lt;/span&gt;
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;function&lt;/span&gt; add( elt : MyClass ) {
        head = &lt;span class="keyword"&gt;new&lt;/span&gt; Cell(elt,head);
    }
}
&lt;span class="comment"&gt;// You can then iterate on your list this way :&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; l : MyCell = mylist.head;
&lt;span class="keyword"&gt;while&lt;/span&gt;( l != null ) {
    &lt;span class="keyword"&gt;var&lt;/span&gt; e : MyClass = l.elt;
    &lt;span class="comment"&gt;// ... do something with e ...&lt;/span&gt;
    l = l.next;
}
&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;First, the good news&amp;nbsp;: using a typed linked list is &lt;strong&gt;2 to 3 times faster&lt;/strong&gt; than using an Array&amp;nbsp;! (if you want to test that in AS3, make sure to type all your variables, the code here is entirely typed thanks to haXe type-inference)&lt;/p&gt;
&lt;p&gt;Now the bad news&amp;nbsp;: you will have a define a &lt;strong&gt;MyList&lt;/strong&gt; and &lt;strong&gt;MyCell&lt;/strong&gt; class for each different class you want to store. So you have to copy/paste the same code again and again. Using &lt;strong&gt;Dynamic&lt;/strong&gt; (or &lt;strong&gt;&lt;/strong&gt;* in AS3) is out of question here since that would require a cast for each reading of an element that would be slow again.&lt;/p&gt;
&lt;p&gt;Current haXe users know that the language have typed arrays in order to ensure type-safety. You can also define your own parametrized classes, so it's pretty easy to write-once the following&amp;nbsp;:&lt;/p&gt;
&lt;pre class="code haxe"&gt;
&lt;span class="comment"&gt;// a cell containing any instance&lt;/span&gt;
&lt;span class="keyword"&gt;class&lt;/span&gt; Cell&amp;lt;T&amp;gt; {
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;var&lt;/span&gt; elt : T;
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;var&lt;/span&gt; next : Cell&amp;lt;T&amp;gt;;
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;function&lt;/span&gt; &lt;span class="keyword"&gt;new&lt;/span&gt;( elt, next ) {
        &lt;span class="keyword"&gt;this&lt;/span&gt;.elt = elt;
        &lt;span class="keyword"&gt;this&lt;/span&gt;.next = next;
    }
}
&lt;span class="comment"&gt;// a list managing a chained list of cells&lt;/span&gt;
&lt;span class="keyword"&gt;class&lt;/span&gt; List&amp;lt;T&amp;gt; {
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;var&lt;/span&gt; head : Cell&amp;lt;T&amp;gt;;
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;function&lt;/span&gt; &lt;span class="keyword"&gt;new&lt;/span&gt;() {
        head = null;
    }
    &lt;span class="comment"&gt;// add an element at the beginning of the list &lt;/span&gt;
    &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;function&lt;/span&gt; add( elt : T ) {
        head = &lt;span class="keyword"&gt;new&lt;/span&gt; Cell(elt,head);
    }
}
&lt;/pre&gt;
&lt;p&gt;The problem is that typed-parameters are only used for compile-time type checking. Since the Flash9 VM does not support them, they disappear in the compiled code and are then replaced by the AS3 &lt;strong&gt;&lt;/strong&gt;* type, so all your accesses to the List will need an additional cast... we're back the problem.&lt;/p&gt;
&lt;p&gt;Thinking about the problem, I was thinking then&amp;nbsp;: why not let the compiler generate a specific version of the List class for each parameter it will be used&amp;nbsp;? This way it would generate a List_User and a Cell_User class that can contains User instances, and so on.... automatically at compile time&amp;nbsp;!&lt;/p&gt;
&lt;p&gt;That approach was proved quite easy to implement, so it works now in haXe. In order to let the user choose between speed and codesize, the default haXe List class has not been modified, but instead a new haxe.FastList class has been added (accessible when compiling for Flash9).&lt;/p&gt;
&lt;p&gt;In order to create your own "generic" classes that will be specialized when used with a type parameter, you can simply have your class implements the haxe.rtti.Generic interface.&lt;/p&gt;
&lt;p&gt;Both haxe.FastList and haxe.rtti.Generic are now on haXe CVS (you can download and compile it to give it a try) and will be part of the 1.19 Release.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&amp;nbsp;: there's a lot of painful things to do when you want to optimize your code to run fast on Flash9. But thanks to haXe inline and generics, it's a lot more easy to do while keeping your code clean and maintainable.&lt;/p&gt;

</content:encoded></item><item><title>Professional haXe and Neko Book</title><link>http://blog.haxe.org/entry/30</link><guid>http://blog.haxe.org/entry/30</guid><dc:date>2008-01-31 13:10:07</dc:date><pubDate>2008-01-31 13:10:07</pubDate><dc:creator>Lee McColl Sylvester</dc:creator><author>Lee McColl Sylvester</author><description>The Wrox Professional haXe and Neko book by Lee McColl Sylvester and Franco Ponticelli, is now available for purchase from Amazon.</description><content:encoded>
&lt;p&gt;The Wrox Professional haXe and Neko book by Lee McColl Sylvester and Franco Ponticelli, is now available for purchase from Amazon.&lt;/p&gt;
&lt;p&gt;This book, having taken a year to write, is the combined efforts of Lee and Franco, with much help from Nicolas Cannasse, Daniel Fischer, Ritchie Turner (aka. Blackdog) and the team at Wiley &amp;amp; Sons. The book is a comprehensive overview of the haXe language and Neko virtual machine, sporting 648 pages of infomation. The chapters include:&lt;/p&gt;

&lt;p&gt;PART I&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Chapter 1:  Introducing haXe&lt;/li&gt;
&lt;li&gt;Chapter 2:  Installing and Using haXe and Neko&lt;/li&gt;
&lt;li&gt;Chapter 3:  Learning the Basics&lt;/li&gt;
&lt;li&gt;Chapter 4:  Controlling the Flow of Information&lt;/li&gt;
&lt;li&gt;Chapter 5:  Delving into Object-Oriented Programming&lt;/li&gt;
&lt;li&gt;Chapter 6:  Organizing Your Code&lt;/li&gt;
&lt;li&gt;Chapter 7:  When Things Go Wrong&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;PART II - Server Side, JavaScript, and Flash, Oh My!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Chapter 8:  Cross Platform Tools&lt;/li&gt;
&lt;li&gt;Chapter 9:  Building Websites in haXe&lt;/li&gt;
&lt;li&gt;Chapter 10: Seperating Design Using Templates&lt;/li&gt;
&lt;li&gt;Chapter 11: Performing Server-Side Trickery&lt;/li&gt;
&lt;li&gt;Chapter 12: Building Interactive Content With Flash&lt;/li&gt;
&lt;li&gt;Chapter 13: Replacing the Need for an IDE&lt;/li&gt;
&lt;li&gt;Chapter 14: More Interactive Content with JavaScript&lt;/li&gt;
&lt;li&gt;Chapter 15: Putting It All Together with haXe Remoting&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;PART III - Extending The Possibilities&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Chapter 16: haXe Advanced Topics&lt;/li&gt;
&lt;li&gt;Chapter 17: Desktop Applications with Neko&lt;/li&gt;
&lt;li&gt;Chapter 18: Desktop Flash with SWHX&lt;/li&gt;
&lt;li&gt;Chapter 19: Multimedia with Neko&lt;/li&gt;
&lt;li&gt;Chapter 20: Extending haXe with C/C++&lt;/li&gt;
&lt;li&gt;Appendix A: Semantic HTML&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Please, if you do buy it, Franco and I would be grateful if you could use our 
associates links. We don't get much for the sales of the book, and to be honest, that's 
not why we wrote it, but if we can buy ourselves books from the sale of this one, then we 
get some reward for our hard work:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/dp/0470122137?tag=buildlabcom-20&amp;amp;camp=14573&amp;amp;creative=327641&amp;amp;linkCode=as1&amp;amp;creativeASIN=0470122137&amp;amp;adid=1EYR8VBVJ7KZ93HVKKY0"&gt;Amazon.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.amazon.co.uk/gp/product/0470122137?ie=UTF8&amp;amp;tag=designrealm-21&amp;amp;linkCode=as2&amp;amp;camp=1634&amp;amp;creative=6738&amp;amp;creativeASIN=0470122137"&gt;Amazon.co.uk&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You'll have to wait about 10 days longer from the .co.uk link, as it is released ten days 
later, but that should make the delivery date about the same if you live in the UK.&lt;/p&gt;
&lt;p&gt;Again, thanks in advance to those that buy it, and we hope you enjoy the book. As always, 
stay tuned to the list for haXe and Neko updates.&lt;/p&gt;

</content:encoded></item><item><title>haXe Talk at 24C3</title><link>http://blog.haxe.org/entry/29</link><guid>http://blog.haxe.org/entry/29</guid><dc:date>2008-01-20 18:08:18</dc:date><pubDate>2008-01-20 18:08:18</pubDate><dc:creator>Nicolas Cannasse</dc:creator><author>Nicolas Cannasse</author><description>&lt;p&gt; Here's the talk I gave about haXe at &lt;a href="http://events.ccc.de/congress/2007/Main_Page"&gt;24C3&lt;/a&gt;. You can &lt;a href="http://chaosradio.ccc.de/24c3_m4v_2281.html"&gt;download&lt;/a&gt; the HD version or view the talk in streaming here : &lt;/p&gt;  &lt;embed styl [...]</description><content:encoded>&lt;p&gt;
Here's the talk I gave about haXe at &lt;a href="http://events.ccc.de/congress/2007/Main_Page"&gt;24C3&lt;/a&gt;. You can &lt;a href="http://chaosradio.ccc.de/24c3_m4v_2281.html"&gt;download&lt;/a&gt; the HD version or view the talk in streaming here :
&lt;/p&gt;

&lt;embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=4962451727046313380&amp;hl=en" flashvars=""&gt; &lt;/embed&gt;
&lt;p&gt;
Enjoy !
&lt;/p&gt;</content:encoded></item><item><title>haxeVideo 1.0</title><link>http://blog.haxe.org/entry/28</link><guid>http://blog.haxe.org/entry/28</guid><dc:date>2007-12-16 02:29:23</dc:date><pubDate>2007-12-16 02:29:23</pubDate><dc:creator>Nicolas Cannasse</dc:creator><author>Nicolas Cannasse</author><description>At last, **haxeVideo 1.0** has now been officially released !   haxeVideo is an opensource video streaming server entirely written in haXe.  You can get it now from http://haxevideo.org !  Features include :  - FLV streaming using RTMP protocol - Web [...]</description><content:encoded>
&lt;p&gt;At last, &lt;strong&gt;haxeVideo 1.0&lt;/strong&gt; has now been officially released&amp;nbsp;!&lt;/p&gt;
&lt;p&gt;haxeVideo is an opensource video streaming server entirely written in haXe.&lt;/p&gt;
&lt;p&gt;You can get it now from &lt;a href="http://haxevideo.org"&gt;http://haxevideo.org&lt;/a&gt; !&lt;/p&gt;
&lt;p&gt;Features include&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;FLV streaming using RTMP protocol&lt;/li&gt;
&lt;li&gt;Webcam and Microphone recording to FLV file&lt;/li&gt;
&lt;li&gt;Live streaming for web conferencing&lt;/li&gt;
&lt;li&gt;light and fast scalable server&lt;/li&gt;
&lt;li&gt;only 50 KB of server source code&amp;nbsp;: modify whatever you need&amp;nbsp;!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Big thanks to the Red5 team and Roberto Saccon for helping me when I had trouble with RTMP implementation&amp;nbsp;!&lt;/p&gt;
&lt;p&gt;And I hope you'll enjoy the opening test video ;)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Nicolas&lt;/em&gt;&lt;/p&gt;

</content:encoded></item><item><title>[OT] Fanfare</title><link>http://blog.haxe.org/entry/27</link><guid>http://blog.haxe.org/entry/27</guid><dc:date>2007-11-21 23:22:23</dc:date><pubDate>2007-11-21 23:22:23</pubDate><dc:creator>Nicolas Cannasse</dc:creator><author>Nicolas Cannasse</author><description>This blog tends to be a bit too much technical sometimes, so what about a little Fanfare for a change ? One for geeks, of course.  [html] &lt;div&gt;&lt;object width="425" height="335"&gt;&lt;param name="movie" value="http://www.dailymotion.com/swf/4cHhXYl8yN2njoyK [...]</description><content:encoded>
&lt;p&gt;This blog tends to be a bit too much technical sometimes, so what about a little Fanfare for a change&amp;nbsp;? One for geeks, of course.&lt;/p&gt;


&lt;div&gt;&lt;object width="425" height="335"&gt;&lt;param name="movie" value="http://www.dailymotion.com/swf/4cHhXYl8yN2njoyKJ"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.dailymotion.com/swf/4cHhXYl8yN2njoyKJ" type="application/x-shockwave-flash" width="425" height="335" allowFullScreen="true" allowScriptAccess="always"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;


</content:encoded></item><item><title>Fast Flash9 Fixed Point Sine</title><link>http://blog.haxe.org/entry/26</link><guid>http://blog.haxe.org/entry/26</guid><dc:date>2007-11-11 23:47:23</dc:date><pubDate>2007-11-11 23:47:23</pubDate><dc:creator>Nicolas Cannasse</dc:creator><author>Nicolas Cannasse</author><description>Recently I've been starting playing a bit with Flash9.   A few months ago, after adapting the haXe compiler to target the AVM2 (which also runs ActionScript3), I wrote the [link hxASM : http://blog.haxe.org/entry/18] library which enable you to write [...]</description><content:encoded>
&lt;p&gt;Recently I've been starting playing a bit with Flash9.&lt;/p&gt;
&lt;p&gt;A few months ago, after adapting the haXe compiler to target the AVM2 (which also runs ActionScript3), I wrote the &lt;a href="http://blog.haxe.org/entry/18"&gt;hxASM&lt;/a&gt; library which enable you to write Flash9 assembler in haXe.&lt;/p&gt;
&lt;p&gt;Yesterday, I started to micro-benchmark some of the most common operations in order to check what kind of thing is expensive and what kind of thing can be done fast.&lt;/p&gt;
&lt;p&gt;I was using some Bench program written in haXe, then generating the corresponding AS3 code by using the &lt;a href="http://haxe.org/tutos/as3_gen"&gt;haXe-to-AS3 Generator&lt;/a&gt;, and comparing the results of both outputs.&lt;/p&gt;
&lt;p&gt;This way, I could find that some of the operations in haXe were a bit underoptimized, so now everything should be fixed on CVS and these improvements will be included in next 1.17 release.&lt;/p&gt;
&lt;p&gt;I was also able to get some interesting conclusions&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;array accesses are not that fast&lt;/li&gt;
&lt;li&gt;static calls are very slow compared to method calls (like 10 times slower). That's a bit strange given that the VM should be able to resolve them at JIT'time and them optimize better&lt;/li&gt;
&lt;li&gt;in particular, while floating point and integer arithmetics operations are very fast, calls to Math functions such as "sin" or "cos" are very slow&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As you know, &lt;a href="http://www.motion-twin.com/projects"&gt;games&lt;/a&gt; and 3D engines use a lot of Math functions, so I was interested in writting an optimized &lt;strong&gt;Math.sin&lt;/strong&gt; function. Using precomputed tables would not work because of array access time, so I was thinking to use some approximative float calculus (like &lt;a href="http://en.wikipedia.org/wiki/Taylor_series"&gt;Taylor series&lt;/a&gt;). After a bit of googling, I found &lt;a href="http://lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine-approximation/"&gt;this blog post&lt;/a&gt; which was exactly what I was looking for. This can be rewrote as the following code (without precomputed constants)&amp;nbsp;:&lt;/p&gt;

&lt;pre class="code haxe"&gt;
&lt;span class="keyword"&gt;function&lt;/span&gt; fastsin( x : Float ) {
   &lt;span class="comment"&gt;// clamp&lt;/span&gt;
   &lt;span class="keyword"&gt;if&lt;/span&gt;( x &amp;lt; -PI ) x += 2*PI &lt;span class="keyword"&gt;else&lt;/span&gt; &lt;span class="keyword"&gt;if&lt;/span&gt;( x &amp;gt; PI ) x -= 2*PI;
   &lt;span class="comment"&gt;// approximate&lt;/span&gt;
   &lt;span class="keyword"&gt;var&lt;/span&gt; sin = (x - x * abs(x) / PI) * 4 / PI;
   &lt;span class="comment"&gt;// adds correction&lt;/span&gt;
   &lt;span class="keyword"&gt;var&lt;/span&gt; fix = sin + .225 * (sin * abs(sin) - sin);
   &lt;span class="comment"&gt;// we're done !&lt;/span&gt;
   &lt;span class="keyword"&gt;return&lt;/span&gt; fix;
}
&lt;/pre&gt;
&lt;p&gt;This code does not calculate exactly a &lt;strong&gt;sin&lt;/strong&gt;, but gives a very very good approximate that can be perfectly used in games or 3D.&lt;/p&gt;

&lt;h2&gt;Clamping&lt;/h2&gt;
&lt;p&gt;First remark&amp;nbsp;: the clamping of value in the [-PI,PI] range is a bit slow and inacurate in the case the value is 10*PI for example.&lt;/p&gt;
&lt;p&gt;So how can we easily clamp a Float value between two bounds&amp;nbsp;?&lt;/p&gt;
&lt;p&gt;Using a modulo does not work very well in that case since we want a mod(2PI). We need then some kind of overflow... just like Flash9 &lt;strong&gt;int&lt;/strong&gt; type which is constraint into the range [-2^31,2^31].&lt;/p&gt;
&lt;p&gt;Does that remind you something&amp;nbsp;? Let's do the maths&amp;nbsp;:&lt;/p&gt;

&lt;pre class="code haxe"&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; range = 2^31 / PI;
x = int(x * range) / range;
&lt;/pre&gt;
&lt;p&gt;And here it is&amp;nbsp;! Superfast accurate clamp&amp;nbsp;!&lt;/p&gt;

&lt;h2&gt;Fixed point&lt;/h2&gt;
&lt;p&gt;Another good thing to know is that integer calculus is a lot faster than floating point calculus, so making the rest of the &lt;strong&gt;fastsin&lt;/strong&gt; operations using integer calculus would be a lot faster.&lt;/p&gt;
&lt;p&gt;But we have floating point values, so how do we turn them into integer operations&amp;nbsp;? By using Fixed Point integers. For those that don't know about it, here how it works&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you convert a float to an int by multiplying it by K=2^15/PI, so you have a 0,000096 precision which should be enough for our fastsin.&lt;/li&gt;
&lt;li&gt;Since our float is between -PI and PI, it will turn into an integer between [-2^15,2^15] which is good since it means we can multiply two of these integers without any overflow.&lt;/li&gt;
&lt;li&gt;addition and substraction works the same, since (a*K)+(b*K) == (a+b)*K&lt;/li&gt;
&lt;li&gt;for multiplication however, you have (a*K)*(b*K) = (a * b) * K * K so once multiplied you have to divise by K which is not very easy here, but there will be some trick.&lt;/li&gt;
&lt;li&gt;once calculus is terminated, you can simply divide your integer by K to get the float result&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let's get things into practice. First, after clamping, we reduce the integer from [-2^31,2^31] to [-2^15,2^15] range&amp;nbsp;:&lt;/p&gt;

&lt;pre class="code haxe"&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; x = int(angle * 2^31 / PI) &amp;gt;&amp;gt; 16;
&lt;span class="comment"&gt;// with constant&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; x = int(angle * 683565275.57643158978229477811035) &amp;gt;&amp;gt; 16;
&lt;/pre&gt;
&lt;p&gt;Then we can perform several simplifications of the &lt;strong&gt;sin&lt;/strong&gt; variable calculus&amp;nbsp;:&lt;/p&gt;

&lt;pre class="code haxe"&gt;
&lt;span class="comment"&gt;// replace x by x/K&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; sin = (x/K - x/K * abs(x/K) / PI) * (4 / PI);
&lt;span class="comment"&gt;// expand&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; sin = (x - x * abs(x) / (PI * K)) * (4 / PI) / K;
&lt;span class="comment"&gt;// replacing K&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; sin = (x - x * abs(x) / (PI * 2^15 / PI)) * (4 / PI) / K;
&lt;span class="comment"&gt;// reducing and multiplying by 2^30/PI&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; sinB = (x - x * abs(x) / 2^15) * (4/PI) * (2^30/PI) / (2^15/PI);
&lt;span class="comment"&gt;// optimizing&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; sinB = (x - ((x * abs(x)) &amp;gt;&amp;gt; 15)) * 41721;
&lt;/pre&gt;
&lt;p&gt;Here, we then have calculated &lt;strong&gt;sinB = sin*2^30/PI&lt;/strong&gt; using only integer calculus. Now that the first part is optimized, we can also continue with the second part&amp;nbsp;:&lt;/p&gt;

&lt;pre class="code haxe"&gt;
&lt;span class="comment"&gt;// replace sin by sinB/(2^30/PI)&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; fix = sinB/(2^30/PI) + .225 * 
            (sinB/(2^30/PI) * abs(sinB/(2^30/PI)) - sinB/(2^30/PI));
&lt;span class="comment"&gt;// expand&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; fix = (.775*sinB + .225*sinB*abs(sinB) / (2^30/PI)) / (2^30/PI);
&lt;span class="comment"&gt;// factorize&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; fix = (sinB + (.225/.775)*PI*sinB*abs(sinB)/2^30) * .775*PI/2^30
&lt;span class="comment"&gt;// factorize&lt;/span&gt;, calculate
&lt;span class="keyword"&gt;var&lt;/span&gt; fix = (sinB + ~0.912*(sinB/2^15)*abs(sinB/2^15)) * .775* PI/2^30
&lt;span class="comment"&gt;// tmp variable&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; sinC = sinB &amp;gt;&amp;gt; 15;
&lt;span class="keyword"&gt;var&lt;/span&gt; fix = (sinB + ~0.912 * sinC * abs(sinC)) * .775*PI/2^30;
&lt;span class="comment"&gt;// one last trick for approximating 0.912 multiplication&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; fix = (sinB + ((sinC * abs(sinC)) &amp;gt;&amp;gt; 9) * 467) * .775*PI/2^30;
&lt;span class="comment"&gt;// now calculate the last division real value&lt;/span&gt;
&lt;span class="keyword"&gt;var&lt;/span&gt; fix = (sinB + ((sinC * abs(sinC)) &amp;gt;&amp;gt; 9) * 467)
&lt;span class="keyword"&gt;return&lt;/span&gt; fix / 441009855.21060102566599663103894;
&lt;/pre&gt;
&lt;p&gt;Let's explain a bit the 0.912 trick here. In fixed point, we want to do only a multiplication by an integer. So we have to find an good balance between precision and speed. So we start calculating all powers of 2 multiplied by 0.912, until we find that (2^9 * 0.912) ~= 467, so we can then substitute 0.912 by 467/2^9, and use a right shift instead of the division.&lt;/p&gt;
&lt;p&gt;Ouch&amp;nbsp;! We're done&amp;nbsp;! Let's write everything down&amp;nbsp;: this is the haXe version (you can't compile it with haXe 1.16 since __int__ was just added on CVS)&amp;nbsp;:&lt;/p&gt;

&lt;pre class="code haxe"&gt;
&lt;span class="keyword"&gt;function&lt;/span&gt; fastsin( x : Float ) {
   &lt;span class="comment"&gt;// clamp to [-2^15,2^15]&lt;/span&gt;
   &lt;span class="keyword"&gt;var&lt;/span&gt; x = (&lt;span class="keyword"&gt;untyped&lt;/span&gt; __int__(angle*683565275.576431589782294)) &amp;gt;&amp;gt; 16;
   &lt;span class="comment"&gt;// approximate&lt;/span&gt;
   &lt;span class="keyword"&gt;var&lt;/span&gt; sinB = (x - ((x * (x&amp;lt;0?-x:x)) &amp;gt;&amp;gt; 15)) * 41721;
   &lt;span class="comment"&gt;// adds correction&lt;/span&gt;
   &lt;span class="keyword"&gt;var&lt;/span&gt; sinC = sinB &amp;gt;&amp;gt; 15;
   &lt;span class="keyword"&gt;var&lt;/span&gt; fix = sinB + (sinC * (sinC&amp;lt;0?-sinC:sinC) &amp;gt;&amp;gt; 9) * 467;
   &lt;span class="comment"&gt;// we're done&lt;/span&gt;
   &lt;span class="keyword"&gt;return&lt;/span&gt; fix / 441009855.21060102566599663103894;
}
&lt;/pre&gt;
&lt;p&gt;Doing some quick tests gives the following&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;approximation works as good as the floating point version, with a difference of less than 0.00129 between the real sinus calculus and the fast one.&lt;/li&gt;
&lt;li&gt;when called as a method, speed compared to Math.sin is &lt;strong&gt;225%&lt;/strong&gt; (more than two times faster), when inlined &lt;strong&gt;320%&lt;/strong&gt; (more than three times faster)&amp;nbsp;!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Bad news and good news&amp;nbsp;!&lt;/h2&gt;
&lt;p&gt;By doing this optimization, we could manage to remove entirely the cost of the static call. It means that putting &lt;strong&gt;fastsin&lt;/strong&gt; inside a static function would go slower that real Math.sin. But the good news is that we can &lt;strong&gt;inline&lt;/strong&gt; the code.&lt;/p&gt;
&lt;p&gt;This is something that haXe will support soon. You will be able to mark &lt;strong&gt;fastsin&lt;/strong&gt; method as &lt;strong&gt;inline&lt;/strong&gt; and each time it's called, it will insert at compiletime in your code the 5 lines of the method body instead of the actual call, giving you the best speedup you can get.&lt;/p&gt;
&lt;p&gt;The bad news is for ActionScript3 users. I don't know why, but even with typing everything to int, some of the integer operations are not correctly optimized by the MXMLC compiler. Hence, it actually performs quite bad...&lt;/p&gt;
&lt;p&gt;Now, a very good news&amp;nbsp;: if you're interested in getting the best performances from Flash9 VM, you will have to use haXe &amp;nbsp;:)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nicolas Cannasse&lt;/strong&gt;&lt;/p&gt;

</content:encoded></item><item><title>EcmaScript 4 and the Web</title><link>http://blog.haxe.org/entry/25</link><guid>http://blog.haxe.org/entry/25</guid><dc:date>2007-11-03 16:50:46</dc:date><pubDate>2007-11-03 16:50:46</pubDate><dc:creator>Nicolas Cannasse</dc:creator><author>Nicolas Cannasse</author><description>Recently was published a proposal for extending the current Javascript language with a good set of new features : classes, optional type system, and a lot more. This proposal is known as [link EcmaScript4 : http://www.ecmascript.org] (ES4) and was bu [...]</description><content:encoded>
&lt;p&gt;Recently was published a proposal for extending the current Javascript language with a good set of new features&amp;nbsp;: classes, optional type system, and a lot more. This proposal is known as &lt;a href="http://www.ecmascript.org"&gt;EcmaScript4&lt;/a&gt; (ES4) and was built by the TG1 discussion group composed of representatives from Mozilla, Adobe, Opera, Microsoft, and maybe a few others.&lt;/p&gt;
&lt;p&gt;While things were going smoothly up to now, there is currently a quite big debate among some of the TG1 participants and other people from the Javascript (JS) community (see the whole public &lt;a href="https://mail.mozilla.org/pipermail/es4-discuss/"&gt;discussion&lt;/a&gt; if you have free time).&lt;/p&gt;
&lt;p&gt;Why this may seem a bit technical, it can have a lot of impact of our (web developers) life.&lt;/p&gt;

&lt;h2&gt;Stakes&lt;/h2&gt;
&lt;p&gt;At first, and in order to understand the situation we are in, there are different kind of conflicting interests at stake, so let's try to sumup a little bit&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Mozilla is pushing for big changes&amp;nbsp;: they are big users of Javascript&amp;nbsp;: a lot of their applications are scripted with JS, they have XUL, ... More language features would help them in their everyday work. And surely they would be happy if ES4 would become the standard for web development.&lt;/li&gt;
&lt;li&gt;Adobe fully supports Mozilla in this push for ES4. For some time now, they are targeting developers with their new products and want people to forget about the whole "proprietary plaform" label that is stick to Flash. Their strategy is then to support a standardized language. They already implemented a reduced ES4 version called ActionScript3 and the Virtual Machine that runs it (Tamarin) has been donated... to Mozilla.&lt;/li&gt;
&lt;li&gt;On the other side, this is exactly what Microsoft is fearing&amp;nbsp;: they have been investing a lot of time and money into their own prioprietary technologies, like C# and more recently released Silverlight which is seen as a Flash competitor. They would not like to see a new language that they don't control, that was designed by an alliance of their competitors, and that (horror) doesn't run yet on .NET&lt;/li&gt;
&lt;li&gt;there are fears that ES4 would "break the web" since it seems that Mozilla want to replace current Firefox JS Virtual Machine (SpiderMonkey) with a new one that would run ES4. ES4 is is supposed to be backward compatible with JS, but when you change implementation, you might get some bugs and incompatibilities anyway, since even with a lot of testing, software is rarely perfect.&lt;/li&gt;
&lt;li&gt;there are others comments for people of the embedding browser market, such as Opera. For obvious reasons, their fears are more about the size of the runtime that would be needed to run ES4, memory consumption etc.&lt;/li&gt;
&lt;li&gt;some JS developers prefer small-steps improvements to one big-step one. For several reasons. One is be pure conservatism, the other is that when your daily technology evolves, you feel huge pressure to keep up-to-date with the latest features. And if you read ES4 proposal, you can see that while you can write plain'old JS, the number of new features to learn is huge, and it would take a lot of time for the average JS programmer to master the language.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I hope that I didn't forget anyone opinion, I didn't include technical discussions about the usefulness of ES4 features but with that many differents point of view it seems already quite complicated.&lt;/p&gt;

&lt;h2&gt;From here, what&amp;nbsp;?&lt;/h2&gt;
&lt;p&gt;As we see, each party has more or less its own internal agenda, which is perfectly normal in an human world. But at this point, the situation is pretty blocked.&lt;/p&gt;
&lt;p&gt;Mozilla and Adobe seems to want to push ES4 up to the end, and Microsoft will not accept it. I personaly don't care about Microsoft opinion EXCEPT that they are the ones doing Internet Explorer (IE), you know, that (still) 80% market share internet browser, the one your users are visiting your website with...&lt;/p&gt;
&lt;p&gt;So, as developers, we're out of luck.&lt;/p&gt;
&lt;p&gt;Mozilla and Adobe thought the same and came up with the ScreamingMonkey project, which is an ES4 runtime that can be installed for Internet Explorer. Nice, but how long will that work&amp;nbsp;? Given that Microsoft has no intention of helping, I can foresee that each IE/Windows update will break something. In short&amp;nbsp;: I'm not sure it's possible in the long term to put a plugin into an application while its owner does not want to hear about it&amp;nbsp;!&lt;/p&gt;
&lt;p&gt;So, as developers, we're out of luck....&lt;/p&gt;

&lt;h2&gt;Another solution&amp;nbsp;?&lt;/h2&gt;
&lt;p&gt;Now, I'll take a bit of time to write about my own (not hidden) agenda.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://haxe.org"&gt;haXe&lt;/a&gt; is a highlevel programming language that has been developed for few years now and which has a still small but growing community of users. One of the particularity of haXe is that it can compiles to Javascript. It means that you get all the benefits&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you are using an highlevel language with compile-time static typing&lt;/li&gt;
&lt;li&gt;the haXe language let you also do dynamic stuff that is helpful for DOM/AJAX implementations&lt;/li&gt;
&lt;li&gt;in the end, you are generating a .js that can be run by all current browsers&lt;/li&gt;
&lt;li&gt;it's open source&lt;/li&gt;
&lt;li&gt;it can interoperate with existing JS libraries&lt;/li&gt;
&lt;li&gt;if you don't like it, simply use Javascript&amp;nbsp;!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;lt;irony&amp;gt;&lt;/p&gt;
&lt;p&gt;So my suggestion to Mozilla and Adobe would be to drop ES4 and use haXe instead&amp;nbsp;:) There's already an open source compiler available, and a Book on the language should be published soon... unless of course haXe features are not good enough, but I'm open to suggestions and discussions on this particular topic.&lt;/p&gt;
&lt;p&gt;&amp;lt;/irony&amp;gt;&lt;/p&gt;

&lt;h3&gt;And developers&amp;nbsp;?&lt;/h3&gt;
&lt;p&gt;More seriously, it's a shame that nobody asks to the main people concerned by such a decision what would they like to have. The main people here being web/JS developers, which as far as I know are not represented in the ES4 commitee.&lt;/p&gt;
&lt;p&gt;That's actually one of the big problem I have with ECMA or W3C. Everything is decided by a group of people that represent corporate interests, then they publish a huge document which is often a bloated specification that only big companies with enough cash can afford to implement.&lt;/p&gt;
&lt;p&gt;What was useful a few years ago in order to ensure intercompability between different proprietary vendors is no longer needed when there is one single open source implementation.&lt;/p&gt;
&lt;p&gt;That does not remove the need for a clear specification that needs to be either respected or modified, but at least that gives additional agility in the process of designing this specification.&lt;/p&gt;
&lt;p&gt;As a language designer, I prefer to experiment long time with a feature, then if it was useful for enough people of the community, it's added to the language. If not it's removed. That's the way software should be designed, at least IMHO.&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;So what would be wise to do now that we're here&amp;nbsp;? My suggestion would be to forget about languages, forget about syntax or features, forget about corporate wars (if possible).&lt;/p&gt;
&lt;p&gt;What are the problems with current Javascript&amp;nbsp;? As for me they are&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;browser apis incompatibilities&lt;/li&gt;
&lt;li&gt;security&lt;/li&gt;
&lt;li&gt;speed (slow)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So why not have every browser vendor sit around the table and resolve first these issues that are the ones really concerning the developers, instead of losing their time and energy in these fights&amp;nbsp;? Then, as for improving the language, I think it would be better if it was a commmunity work, since corporations can fight between them but no one has the interest to fight against the developers community.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nicolas Cannasse&lt;/strong&gt;&lt;/p&gt;

</content:encoded></item></channel></rss>