{"id":1117,"date":"2008-12-18T11:36:30","date_gmt":"2008-12-18T10:36:30","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/1117-first-steps-with-adobe-alchemy-good-news-and-bad.html"},"modified":"2008-12-18T11:36:30","modified_gmt":"2008-12-18T10:36:30","slug":"first-steps-with-adobe-alchemy-good-news-and-bad","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/1117-first-steps-with-adobe-alchemy-good-news-and-bad.html","title":{"rendered":"First steps with Adobe Alchemy: good news and bad"},"content":{"rendered":"<p>I\u2019m fascinated by Adobe\u2019s <a href=\"http:\/\/labs.adobe.com\/technologies\/alchemy\/\" target=\"_blank\">Alchemy<\/a> project, which compiles C and C++ code into ActionScript, and stayed up late last night to give it a try. I used Ubuntu Linux, which felt brave since the <a href=\"http:\/\/labs.adobe.com\/wiki\/index.php\/Alchemy:Documentation:Getting_Started\" target=\"_blank\">instructions<\/a> are for Windows (using <a href=\"http:\/\/www.cygwin.com\/\" target=\"_blank\">Cygwin<\/a>, which enables somewhat Unix-like development) or Mac. <\/p>\n<p>Techie note: It took me a while to get going; like a number of others I ran into a configuration problem, the symptom being that you type alc-on, which is meant to enable the special Alchemy version of <a href=\"http:\/\/gcc.gnu.org\/\" target=\"_blank\">GCC<\/a> (the standard open source C compiler), but instead get \u201cCommand not found\u201d. In the end I ran the command:<\/p>\n<blockquote>\n<p>source $ALCHEMY_HOME\/alchemy-setup<\/p>\n<\/blockquote>\n<p>directly from the terminal instead of in my bash profile, and that fixed it. The command alc-on is actually an alias created by this setup script.<\/p>\n<p>After that it was relatively plain sailing. I used a recent version of the <a href=\"http:\/\/www.adobe.com\/products\/flex\/flexdownloads\/#sdk\" target=\"_blank\">Flex 3 SDK<\/a>, and adapted the stringecho.c example to create a countprimes function, because I was curious to see how it would compare to <a href=\"http:\/\/www.itwriting.com\/primetest\/index.html\" target=\"_blank\">other results<\/a>.<\/p>\n<p>The result of my efforts was a Flex library called primetest.swc. I copied this to my Windows box, where I have Flex Builder installed. I <a href=\"http:\/\/blog.promethe.net\/2008\/08\/21\/work-with-flash-10-in-flex-builder-3\/\" target=\"_blank\">configured Flex Builder<\/a> to use Flash Player 10 and the Flex 3.2 SDK. Then I modified the prime-counting applet so I could compare the Alchemy version of the function with ActionScript. Once you have the .swc, the Alchemy code is easy to use:<\/p>\n<blockquote>\n<p>import cmodule.primetest.CLibInit;<\/p>\n<p>\/\/code omitted<\/p>\n<p>if (chkAlchemy.selected)      <br \/>{       <br \/>&#160;&#160;&#160; var loader:CLibInit = new CLibInit;       <br \/>&#160;&#160;&#160; var lib:Object = loader.init();       <br \/>&#160;&#160;&#160; numprimes = lib.countprimes(n);       <br \/>}       <br \/>else       <br \/>{       <br \/>&#160;&#160;&#160; numprimes = countprimes_as(n);       <br \/>}<\/p>\n<\/blockquote>\n<p>Then I tried the application. Note this is not using the debug player.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.itwriting.com\/images\/alchemy_primes.gif\" \/> <\/p>\n<p>As you can see, the Alchemy code is slightly slower than ActionScript. I also tried this with a higher value (10,000,000) and got 34.95 secs for Alchemy versus 32.59 secs for ActionScript.<\/p>\n<p>Conclusions? First, despite the slower performance, Alchemy is mighty impressive. Let\u2019s not forget the intent of Alchemy to enable reuse of C and C++ libraries; it is not just about speed.<\/p>\n<p>Second, note that Alchemy is still a research project and may get faster. Further, I may have missed some tricks in my code.<\/p>\n<p>Third, note that this sort of tight loop is ideal for just-in-time compilation and really should run at speeds close to that of native code anyway. In Silverlight or Java it does.<\/p>\n<p>So does the test prove anything? Well, it shows that Alchemy won\u2019t always speed your code, which raises the question: in what circumstances will it be a performance win? There is a useful post <a href=\"http:\/\/www.adobe.com\/cfusion\/webforums\/forum\/messageview.cfm?forumid=72&amp;catid=755&amp;threadid=1407064&amp;enterthread=y\" target=\"_blank\">here<\/a> from Joe Steele:<\/p>\n<blockquote>\n<p>The potential wins on performance are if you are operating on a large ByteArray (because of the optimized ByteArray opcodes) or if your code is doing a lot of boxing\/unboxing (which largely goes away with Alchemys arg passing model). You are ultimately getting ActionScript out so if you already have hand-tuned ActionScript that avoids boxing\/unboxing and is dealing with small chunks of data, you are not likely to beat that with Alchemy.<\/p>\n<\/blockquote>\n<p>My experience is in line with his comments.<\/p>\n<p>The general claim made in this <a href=\"http:\/\/www.adobe.com\/cfusion\/webforums\/forum\/messageview.cfm?forumid=72&amp;catid=755&amp;threadid=1407064&amp;enterthread=y\" target=\"_blank\">thread<\/a> (see Brandan Hall\u2019s post) is that:<\/p>\n<blockquote>\n<p>&#8230; under favorable conditions [Alchemy] runs 10 times slower than native code but 10 times faster than ActionScript<\/p>\n<\/blockquote>\n<p>I guess the big question, from a performance perspective, is how much real-world code that is worth optimizing (because it does intensive processing that the user notices) falls into the \u201cfavorable conditions\u201d category. If that turns out to be not many, we may have to abandon the idea of Alchemy as a performance fix, and just enjoy the portability it enables.<\/p>\n<div class=\"wlWriterEditableSmartContent\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:14c3aca5-caf2-4dde-a8d3-09494e647816\" style=\"padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px\">Technorati tags: <a href=\"http:\/\/technorati.com\/tags\/adobe\" rel=\"tag\">adobe<\/a>, <a href=\"http:\/\/technorati.com\/tags\/alchemy\" rel=\"tag\">alchemy<\/a>, <a href=\"http:\/\/technorati.com\/tags\/performance\" rel=\"tag\">performance<\/a>, <a href=\"http:\/\/technorati.com\/tags\/silverlight\" rel=\"tag\">silverlight<\/a>, <a href=\"http:\/\/technorati.com\/tags\/java\" rel=\"tag\">java<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019m fascinated by Adobe\u2019s Alchemy project, which compiles C and C++ code into ActionScript, and stayed up late last night to give it a try. I used Ubuntu Linux, which felt brave since the instructions are for Windows (using Cygwin, which enables somewhat Unix-like development) or Mac. Techie note: It took me a while to &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/1117-first-steps-with-adobe-alchemy-good-news-and-bad.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">First steps with Adobe Alchemy: good news and bad<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1117","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/1117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=1117"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/1117\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=1117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=1117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=1117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}