<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ismael Juma</title>
	<atom:link href="http://blog.juma.me.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.juma.me.uk</link>
	<description></description>
	<lastBuildDate>Fri, 18 Dec 2009 08:52:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.juma.me.uk' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/df49f5cf356a61e77002006a98dabab0?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ismael Juma</title>
		<link>http://blog.juma.me.uk</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.juma.me.uk/osd.xml" title="Ismael Juma" />
	<atom:link rel='hub' href='http://blog.juma.me.uk/?pushpress=hub'/>
		<item>
		<title>New JVM options and Scala iteration performance</title>
		<link>http://blog.juma.me.uk/2009/10/26/new-jvm-options-and-scala-iteration-performance/</link>
		<comments>http://blog.juma.me.uk/2009/10/26/new-jvm-options-and-scala-iteration-performance/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 14:00:27 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[jvm]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[Compressed Oops]]></category>
		<category><![CDATA[escape analysis]]></category>
		<category><![CDATA[iteration]]></category>
		<category><![CDATA[optimise]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=125</guid>
		<description><![CDATA[Internal iterators like foreach tend to do very well in micro-benchmarks on the JVM. In fact, they often do as well as the equivalent manual while or for loop. There is a catch, however, and it&#8217;s easy to miss it in micro-benchmarks. A few months ago, David MacIver forwarded an email from Martin Odersky to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=125&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Internal iterators like foreach tend to do very well in micro-benchmarks on the JVM. In fact, they often do as well as the equivalent manual while or for loop. There is a catch, however, and it&#8217;s easy to miss it in micro-benchmarks.</p>
<p>A few months ago, <a href="http://www.drmaciver.com/">David MacIver</a> forwarded an <a href="http://thread.gmane.org/gmane.comp.lang.scala.internals/865">email</a> from <a href="http://en.wikipedia.org/wiki/Martin_Odersky">Martin Odersky</a> to the scala-internals mailing list about this. The problem as described by Martin:</p>
<p>&#8220;The reason seems to be that the foreach itself is not inlined, so the call to the closure becomes megamorphic and therefore slow.&#8221;</p>
<p>I was curious about the benchmarks used to measure this and <a href="http://people.epfl.ch/tiark.rompf">Tiark Rompf</a> (who had performed the measurements) provided the <a href="http://lamp.epfl.ch/~rompf/vector2/">source code</a>. I said I&#8217;d try to take a look the next weekend and I did it&#8230; more than 3 months later. Well, better late than never. ;)</p>
<p>There are 3 benchmarks:</p>
<ul>
<li>Benchmark A: traverse a collection with N elements</li>
<li>Benchmark B: traverse a collection with N elements, inside the loop/closure traverse another collection with N2 elements 3 times</li>
<li>Benchmark C: build a collection (front to back) of N elements</li>
</ul>
<p>Various approaches are used for each benchmark with various collections types. One weakness of the these benchmarks is that they don&#8217;t include a verification mechanism to ensure that all benchmarks produce the same result. However, they include code that tries to prevent the JIT from performing unfair optimisations (e.g. print something if an element in the collection matches a certain condition).</p>
<p>The <a href="http://lamp.epfl.ch/~rompf/vector2/vector-summary.txt">original results</a> produced by Tiark can be found <a href="http://lamp.epfl.ch/~rompf/vector2/vector-summary.txt">here</a>.</p>
<p>I added a few benchmarks that use plain arrays (RawArrayIndexed, RawArrayForeach, RawArrayForeachMega), made minor changes to the scripts and pushed the code to a <a href="http://github.com/ijuma/benchmark">GitHub repository</a>. I left the rest of the Scala code as it was to make it easy to compare with the original results and ran the benchmark with various JVM settings to see what effect they would have. All the tests shared the following:</p>
<ul>
<li>Dual quad-core Xeon E5462 2.80GHz</li>
<li>14 GB RAM</li>
<li>Fedora 11</li>
<li>Scala 2.8.0.r19261</li>
<li>Revision <a href="http://github.com/ijuma/benchmark/commit/59521431f5c118b73e35b0b396e3efd6aecec3dd">59521431f5c118b73e35b0b396e3efd6aecec3dd</a> of project</li>
<li>64-bit JDK 6 Update 18 early access b03</li>
<li>JVM base settings: -Xms1G -Xmx1G -XX:+UseParallelGC -XX:+UseParallelOldGC</li>
</ul>
<p>JDK 6 Update 18 is scheduled to be released on <a href="https://jdk6.dev.java.net/">Q4, 2009</a> and it includes HotSpot 16. Even though JDK 6 Update 14 (HotSpot 14) introduced <a href="http://blog.juma.me.uk/2008/10/14/32-bit-or-64-bit-jvm-how-about-a-hybrid/">compressed references</a> and <a href="http://blog.juma.me.uk/2008/12/17/objects-with-no-allocation-overhead/">scalar replacement</a>, HotSpot 16 includes <a href="http://blog.juma.me.uk/2009/04/03/load-unsigned-and-better-compressed-oops/">improved compressed references</a> and many crucial fixes to both features. According to my testing these features are now approaching production-level stability and the OpenJDK engineers seem to agree as they are both enabled by default in HotSpot 17 (which will eventually hit JDK6 too).</p>
<p>Interested in how these features would affect the performance in these benchmarks, I ran them with various combinations. I also added Scala&#8217;s compiler -optimise flag in some cases.</p>
<p>The original benchmark from Tiark used 3 collection types: array (java.util.ArrayList), list (scala.List, immutable single linked list) and vector (earlier version of immutable vector that has recently been added to Scala 2.8). I added JVM arrays and they are shown as &#8220;rawarray&#8221; in the charts. Finally, we get to the actual numbers.</p>
<div id="attachment_127" class="wp-caption alignnone" style="width: 505px"><a href="http://ijuma.files.wordpress.com/2009/10/benchmarka.png"><img src="http://ijuma.files.wordpress.com/2009/10/benchmarka.png?w=495&#038;h=204" alt="Benchmark A" title="Benchmark A" width="495" height="204" class="size-full wp-image-127" /></a><p class="wp-caption-text">Click on chart for expanded version</p></div>
<p>There are some interesting data points here:</p>
<ol>
<li>Compressed references is a _huge_ win. RawArrayIndexed went from 500ms to 142ms and many of the vector operations were much faster.</li>
<li>Escape analysis (which enables scalar replacement) doesn&#8217;t seem to have much of an effect.</li>
<li>scalac -optimise doesn&#8217;t seem to have much of an effect.</li>
<li>foreach is misleadingly fast in micro-benchmarks, but it&#8217;s easy to bring it down to earth. RawArrayForeach performs similarly to RawArrayIndexed, but RawArrayForeachMega is 10 times slower. The latter simply calls foreach with a few different anonymous functions during the collection creation phase causing the call site to become megamorphic. Once this happens, the only hope for good performance is that the foreach method gets inlined and it doesn&#8217;t seem to happen here. With this in mind, it seems like <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1338">ticket 1338</a> (Optimize simple for loops) is a good idea.</li>
</ol>
<div id="attachment_131" class="wp-caption alignnone" style="width: 505px"><a href="http://ijuma.files.wordpress.com/2009/10/benchmarkb.png"><img src="http://ijuma.files.wordpress.com/2009/10/benchmarkb.png?w=495&#038;h=261" alt="Benchmark B" title="Benchmark B" width="495" height="261" class="size-full wp-image-131" /></a><p class="wp-caption-text">Click on chart for expanded version</p></div>
<p>Once again, compressed references are a large factor in some benchmarks (halving the time taken in some cases).</p>
<p>The new bit of information is that scalac -optimise causes a huge improvement in VectorForeachFast and VectorForeachFastProtect. This makes sense once one considers one of the findings from the previous benchmark. We said that inlining of foreach is of extreme importance once a call site is megamorphic and this is precisely what -optimise does in this case (and the JVM fails to do so at runtime otherwise). Sadly, -optimise cannot do this safely in many cases as it&#8217;s shown by the results for VectorForeach.</p>
<div id="attachment_132" class="wp-caption alignnone" style="width: 505px"><a href="http://ijuma.files.wordpress.com/2009/10/benchmarkc.png"><img src="http://ijuma.files.wordpress.com/2009/10/benchmarkc.png?w=495&#038;h=198" alt="Benchmark C" title="Benchmark C" width="495" height="198" class="size-full wp-image-132" /></a><p class="wp-caption-text">Click on chart for expanded version</p></div>
<p>Once again, compressed references provide a nice boost. Seems like this option is a winner in 64-bit JVMs (if you don&#8217;t need a heap larger than 32GB), it saves memory and gives better performance. The usual disclaimer applies though, you should benchmark your own application instead of relying on micro-benchmarks when deciding what JVM options to use.</p>
<p>The <a href="http://github.com/ijuma/benchmark/blob/22e0181ba5981195b67ab9ce230b90eaeae643d5/savedOutput/rompfTimingsScript-20091025.txt">complete results</a> are also available. Feel free to play with the <a href="http://github.com/ijuma/benchmark">source code</a> and provide your own numbers, fixes and/or improvements.</p>
<br />Posted in jvm, scala Tagged: Compressed Oops, escape analysis, iteration, jvm, optimise, performance, scala <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/125/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=125&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2009/10/26/new-jvm-options-and-scala-iteration-performance/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>

		<media:content url="http://ijuma.files.wordpress.com/2009/10/benchmarka.png" medium="image">
			<media:title type="html">Benchmark A</media:title>
		</media:content>

		<media:content url="http://ijuma.files.wordpress.com/2009/10/benchmarkb.png" medium="image">
			<media:title type="html">Benchmark B</media:title>
		</media:content>

		<media:content url="http://ijuma.files.wordpress.com/2009/10/benchmarkc.png" medium="image">
			<media:title type="html">Benchmark C</media:title>
		</media:content>
	</item>
		<item>
		<title>Configgy for Scala 2.8</title>
		<link>http://blog.juma.me.uk/2009/10/25/configgy-for-scala-2-8/</link>
		<comments>http://blog.juma.me.uk/2009/10/25/configgy-for-scala-2-8/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 12:17:57 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[configgy]]></category>
		<category><![CDATA[scala 2.8]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=120</guid>
		<description><![CDATA[I wanted to use Configgy with Scala 2.8, so I created a branch in my GitHub repository: http://github.com/ijuma/configgy/tree/scala-2.8 The main code now compiles, but the tests and the build system have to be updated still. I&#8217;m not particularly familiar with Ivy, so if someone else wants to do that, I won&#8217;t complain. ;) The tests [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=120&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I wanted to use <a href="http://github.com/ijuma/configgy/tree/scala-2.8">Configgy with Scala 2.8</a>, so I created a branch in my GitHub repository:</p>
<p><a href="http://github.com/ijuma/configgy/tree/scala-2.8">http://github.com/ijuma/configgy/tree/scala-2.8</a></p>
<p>The main code now compiles, but the tests and the build system have to be updated still.</p>
<p>I&#8217;m not particularly familiar with Ivy, so if someone else wants to do that, I won&#8217;t complain. ;)</p>
<p>The tests use specs and Eric has already released a <a href="http://code.google.com/p/specs/downloads/list">binary for 2.8.0</a>.</p>
<p><strong>Update:</strong> I filed an <a href="http://github.com/robey/configgy/issues/#issue/14">issue</a> upstream to track 2.8 support.</p>
<p><strong>Update 2:</strong> The branch has been updated to Scala 2.8.0.Beta1-RC3 along with the build system and the tests pass. Thanks to paulp for tracking an issue that was taking place because the stack order changed in Scala 2.8.0.</p>
<br />Posted in scala Tagged: configgy, scala, scala 2.8 <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/120/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=120&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2009/10/25/configgy-for-scala-2-8/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Scala 2.7.4-rc1 released</title>
		<link>http://blog.juma.me.uk/2009/04/16/scala-274-rc1-released/</link>
		<comments>http://blog.juma.me.uk/2009/04/16/scala-274-rc1-released/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 10:04:28 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=113</guid>
		<description><![CDATA[Scala 2.7.4-rc1 has been released. It incorporates a few important fixes related to serialization of anonymous functions and generation of Java generics, but the big change is the improved Scala plugin Scala IDE for Eclipse. This means that my backport is now obsolete. The announcement contains all the juicy information. Posted in eclipse, scala Tagged: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=113&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Scala 2.7.4-rc1 has been <a href="http://www.scala-lang.org/node/1493">released</a>. It incorporates a few important fixes related to serialization of anonymous functions and generation of Java generics, but the big change is the improved <del>Scala plugin</del> Scala IDE for Eclipse. This means that my <a href="http://blog.juma.me.uk/2009/02/18/scala-plugin-for-eclipse-snapshot-r17139/">backport</a> is now obsolete.</p>
<p>The <a href="http://www.scala-lang.org/node/1493">announcement</a> contains all the juicy information.</p>
<br />Posted in eclipse, scala Tagged: eclipse, scala <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=113&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2009/04/16/scala-274-rc1-released/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Twitter</title>
		<link>http://blog.juma.me.uk/2009/04/15/twitter/</link>
		<comments>http://blog.juma.me.uk/2009/04/15/twitter/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 05:46:06 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=110</guid>
		<description><![CDATA[After resisting for a while, I have started using twitter. It&#8217;s useful to be able to contribute to some of the &#8220;conversations&#8221; that go on over there, even if I am not particularly fond of the character limit. Posted in Uncategorized Tagged: twitter<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=110&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>After resisting for a while, I have <a href="http://twitter.com/ijuma">started using twitter</a>. It&#8217;s useful to be able to contribute to some of the &#8220;conversations&#8221; that go on over there, even if I am not particularly fond of the character limit.</p>
<br />Posted in Uncategorized Tagged: twitter <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=110&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2009/04/15/twitter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Load unsigned and better Compressed Oops</title>
		<link>http://blog.juma.me.uk/2009/04/03/load-unsigned-and-better-compressed-oops/</link>
		<comments>http://blog.juma.me.uk/2009/04/03/load-unsigned-and-better-compressed-oops/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 09:46:42 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[jvm]]></category>
		<category><![CDATA[Compressed Oops]]></category>
		<category><![CDATA[hotspot]]></category>
		<category><![CDATA[load unsigned]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=107</guid>
		<description><![CDATA[The HotSpot engineers are constantly working on improving performance. I noticed two interesting commits recently: Vladimir Kozlov improved Compressed Oops so that it doesn&#8217;t need to do encoding/decoding if the heap is smaller than 4GB and to reduce branches/checks if the heap is between 4GB and 32GB. The end result is that 64-bit now surpasses [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=107&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>The HotSpot engineers are constantly working on improving performance. I noticed two interesting commits recently:</p>
<p>Vladimir Kozlov <a href="http://permalink.gmane.org/gmane.comp.java.openjdk.hotspot.compiler.devel/875">improved Compressed Oops</a> so that it doesn&#8217;t need to do encoding/decoding if the heap is smaller than 4GB and to reduce branches/checks if the heap is between 4GB and 32GB. The end result is that <a href="http://blogs.sun.com/dagastine/entry/java_rocks_intel_nehalem1">64-bit now surpasses 32-bit performance</a> in more situations. See my entry about <a href="http://blog.juma.me.uk/2008/10/14/32-bit-or-64-bit-jvm-how-about-a-hybrid/">Compressed Oops</a> if you don&#8217;t know what I&#8217;m talking about. :)</p>
<p>Christian Thalinger <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6797305">added support for load unsigned</a> in the -server JIT. This means that things like bytearray[i] &amp; 0xFF and intarray[i] &amp; 0xFFFFFFFF (necessary since JVM bytecode doesn&#8217;t support unsigned types) can be transformed into load unsigned operations to avoid the performance penalty. This can make a decent difference in some cases (e.g. charset operations).</p>
<br />Posted in jvm Tagged: Compressed Oops, hotspot, jvm, load unsigned, performance <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/107/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=107&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2009/04/03/load-unsigned-and-better-compressed-oops/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Json serialization/deserialization faster than protocol buffers?</title>
		<link>http://blog.juma.me.uk/2009/03/25/json-serializationdeserialization-faster-than-protocol-buffers/</link>
		<comments>http://blog.juma.me.uk/2009/03/25/json-serializationdeserialization-faster-than-protocol-buffers/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 10:47:13 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[protocol buffers]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=91</guid>
		<description><![CDATA[I was reading the The Book of JOSH and saw the following statement: &#8220;Json delivers on what XML promised. Simple to understand, effective data markup accessible and usable by human and computer alike. Serialization/Deserialization is on par with or faster then XML, Thrift and Protocol Buffers.&#8221; That seemed a bit too definite for my taste. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=91&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I was reading the <a href="http://thegreylensmansview.blogspot.com/2009/02/book-of-josh.html">The Book of JOSH</a> and saw the following statement:</p>
<p>&#8220;Json delivers on what XML promised. Simple to understand, effective data markup accessible and usable by human and computer alike. Serialization/Deserialization is on par with or faster then XML, Thrift and Protocol Buffers.&#8221;</p>
<p>That seemed a bit too definite for my taste. There are so many variables that can affect the results that I was interested in more information, so I <a href="http://thegreylensmansview.blogspot.com/2009/02/book-of-josh.html?showComment=1237841220000#c2489295053603640559">asked</a> for it and eventually got an <a href="http://thegreylensmansview.blogspot.com/2009/02/book-of-josh.html?showComment=1237898820000#c926785339918676205">answer</a>.</p>
<p>I had a brief look at the <a href="http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking">benchmark</a> referenced and that was enough to come up with some talking points. To make it easier to follow, I will just compare protocol buffers and json (jackson). I started by running the benchmark in my machine (java 1.6.0_14-ea-b03): </p>
<table>
<tr>
<th></th>
<th>Object create</th>
<th>Serialization</th>
<th>Deserialization</th>
<th>Serialized Size</th>
</tr>
<tr>
<td>protobuf</td>
<td>312.95730</td>
<td>3052.26500</td>
<td>2340.84600</td>
<td>217</td>
</tr>
<tr>
<td>json</td>
<td>182.64535</td>
<td>2284.88300</td>
<td>3362.31850</td>
<td>310</td>
</tr>
</table>
<p>Ok, so json doesn&#8217;t seem to be faster on deserialization and the size is almost 50% bigger (a big deal if the network is the bottleneck as is often the case). Why is serialization of protobuf so slow though? Let&#8217;s see the code:</p>
<pre class="brush: java;">
    public byte[] serialize(MediaContent content, ByteArrayOutputStream baos) throws IOException
    {
        content.writeTo(baos);
        return baos.toByteArray();
    }
</pre>
<p>How about we replace that with content.toByteArray()?</p>
<table>
<tr>
<th></th>
<th>Object create</th>
<th>Serialization</th>
<th>Deserialization</th>
<th>Serialized Size</th>
</tr>
<tr>
<td>protobuf</td>
<td>298.89330</td>
<td>2087.79800</td>
<td>2339.44450</td>
<td>217</td>
</tr>
<tr>
<td>json (jackson)</td>
<td>174.49190</td>
<td>2482.53350</td>
<td>3599.90800</td>
<td>310</tr>
</table>
<p>That&#8217;s more like it. Let&#8217;s try something a bit more exotic just for fun and add XX:+DoEscapeAnalysis:</p>
<table>
<tr>
<th></th>
<th>Object create</th>
<th>Serialization</th>
<th>Deserialization</th>
<th>Serialized Size</th>
</tr>
<tr>
<td>protobuf</td>
<td>260.51330</td>
<td>1925.32300</td>
<td>2302.74250</td>
<td>217</td>
</tr>
<tr>
<td>json (jackson)</td>
<td>176.20370</td>
<td>2385.99750</td>
<td>3647.01700</td>
<td>310</td>
</tr>
</table>
<p>That reduces some of the cost of object creation for protobuf, but it&#8217;s still substantially slower than json. This is not hard to believe because of the builder pattern employed by the Java classes generated by protocol buffers, but I haven&#8217;t investigated it in more detail. In any case, protocol buffers is better in 3 of the measures for this particular benchmark.</p>
<p>What does this mean? Not a lot. As usual, where performance is important, you should create benchmarks that mirror your application and environment. I just couldn&#8217;t let the blanket &#8220;json is on par with or faster than&#8230;&#8221; statement pass without a bit of scrutiny. ;) </p>
<br />Posted in java, programming, scala Tagged: json, performance, protocol buffers <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/91/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=91&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2009/03/25/json-serializationdeserialization-faster-than-protocol-buffers/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>MercurialEclipse 1.3.1019</title>
		<link>http://blog.juma.me.uk/2009/02/18/mercurialeclipse-131019/</link>
		<comments>http://blog.juma.me.uk/2009/02/18/mercurialeclipse-131019/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 19:31:00 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[eclipse]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=83</guid>
		<description><![CDATA[With the talk about DVCSs as active as ever in the Eclipse world, I thought I&#8217;d mention the release of MercurialEclipse 1.3.1019. It still lacks quite a bit of polish, but it already supports a decent amount of features. Even though Mercurial doesn&#8217;t have as much momentum as Git, it has been adopted by a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=83&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>With the <a href="http://www.lunar-ocean.com/letter-to-the-stp-pmc-please-express-interest-over-a-dvcs/">talk</a> <a href="http://intellectualcramps.blogspot.com/2009/02/dvcs-talk-is-heating-up-again.html">about</a> <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=257706">DVCSs</a> <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=249745">as active as ever</a> in the Eclipse world, I thought I&#8217;d mention the release of <a href="http://groups.google.com/group/mercurialeclipse/browse_thread/thread/1ff2215fd51e93c4/da101d6801ce9ac8?show_docid=da101d6801ce9ac8">MercurialEclipse 1.3.1019</a>. It still lacks quite a bit of polish, but it already supports a decent amount of <a href="http://trac-hg.assembla.com/mercurialeclipse/wiki/Documentation">features</a>.</p>
<p>Even though <a href="http://www.selenic.com/mercurial/wiki/">Mercurial</a> doesn&#8217;t have as much momentum as Git, it has been <a href="http://www.selenic.com/mercurial/wiki/index.cgi/ProjectsUsingMercurial">adopted by a respectable amount of projects</a> (including Mozilla, Netbeans and OpenJDK).</p>
<br />Posted in eclipse  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=83&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2009/02/18/mercurialeclipse-131019/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Scala plugin for Eclipse snapshot r17139</title>
		<link>http://blog.juma.me.uk/2009/02/18/scala-plugin-for-eclipse-snapshot-r17139/</link>
		<comments>http://blog.juma.me.uk/2009/02/18/scala-plugin-for-eclipse-snapshot-r17139/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 17:22:26 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[eclipse plugin]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=76</guid>
		<description><![CDATA[The snapshot of the Scala plugin for Eclipse that I posted a few days ago had a couple of annoying bugs. Here&#8217;s a new one build (note that it&#8217;s an Eclipse update site, so no point in trying to access it with a browser) from revision 17139 of the trunk of the plugin with the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=76&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>The snapshot of the Scala plugin for Eclipse that I <a href="http://blog.juma.me.uk/2009/02/14/scala-plugin-snapshot/">posted</a> a few days ago had a couple of annoying bugs. <a href="http://juma.me/scala.update">Here&#8217;s a new one build</a>  (note that it&#8217;s an Eclipse update site, so no point in trying to access it with a browser) from revision 17139 of the trunk of the plugin with the compiler and standard libraries from the 2.7.x branch.</p>
<p>Miles has been busy once again and fixes included since the last build are <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1717">1717</a>, <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1233">1233</a>, <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1636">1636</a>, <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1662">1662</a>, <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1716">1716</a>, <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1627">1627</a>, <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1534">1534</a>, <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1410">1410</a>, <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1516">1516</a>, <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1483">1483</a> and <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1253">1253</a>.</p>
<p><strong>Update: </strong> New build published that includes fix for <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1741">ticket 1741</a>. Uninstallation followed by installation may be required if p2 starts giving cryptic errors (it seems like it doesn&#8217;t handle well the case where the update site is replaced). Sorry about that.</p>
<p><strong>Update 2: </strong> With the release of <a href="http://www.scala-lang.org/node/1493">Scala 2.7.4-rc1</a>, this backport is obsolete.</p>
<br />Posted in eclipse, scala Tagged: eclipse plugin, scala <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=76&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2009/02/18/scala-plugin-for-eclipse-snapshot-r17139/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Scala plugin snapshot</title>
		<link>http://blog.juma.me.uk/2009/02/14/scala-plugin-snapshot/</link>
		<comments>http://blog.juma.me.uk/2009/02/14/scala-plugin-snapshot/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 02:52:17 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[eclipse plugin]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=68</guid>
		<description><![CDATA[Miles Sabin has recently committed the Equinox Aspects-based approach to JDT integration for the Scala plugin to trunk. This approach is similar to the one used by the AJDT as described by Andrew Eisenberg. Soon after that commit, Miles embarked on a bug-killing mission. Nightlies are available from the usual place, but they rely on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=68&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://milessabin.com">Miles Sabin</a> has recently <a href="http://www.nabble.com/-scala-tools--Heads-up:-Equinox-Aspects-based-Eclipse-plugin-build-now-on-trunk-td21853596.html">committed</a> the Equinox Aspects-based approach to JDT integration for the Scala plugin to trunk. This approach is similar to the one used by the AJDT as <a href="http://contraptionsforprogramming.blogspot.com/2009/02/extending-jdt-part-i.html">described</a> by Andrew Eisenberg.</p>
<p>Soon after that commit, Miles embarked on a <a href="https://lampsvn.epfl.ch/trac/scala/query?status=closed&amp;component=Eclipse+plugin&amp;order=changetime&amp;col=id&amp;col=summary&amp;col=type&amp;col=changetime&amp;owner=milessabin&amp;desc=1">bug-killing mission</a>. Nightlies are available from the <a href="http://www.scala-lang.org/downloads/distrib/files/nightly/scala.update/">usual place</a>, but they rely on the trunk of the compiler and standard library. With APIs still in flux, it would be nice to be able to use the improved plugin with the compiler and standard library from the 2.7.x branch (this includes a few important fixes added after the 2.7.3 release).</p>
<p>Since it seemed like no-one else had time to do that in the near future, I did it myself. It&#8217;s available <a href="http://juma.me/scala.update">here</a> in case it&#8217;s useful for anyone else. In the interest of full disclosure, I applied the following patch to the plugin:</p>
<p><code><br />
Index: META-INF/MANIFEST.MF<br />
===================================================================<br />
--- META-INF/MANIFEST.MF	(revision 17110)<br />
+++ META-INF/MANIFEST.MF	(working copy)<br />
@@ -34,8 +34,8 @@<br />
  org.eclipse.ui.navigator.resources,<br />
  org.eclipse.ui.views,<br />
  org.eclipse.ui.workbench.texteditor,<br />
- scala.library,<br />
- scala.tools.nsc<br />
+ scala.library;bundle-version="[2.7.3,2.7.4)",<br />
+ scala.tools.nsc;bundle-version="[2.7.3,2.7.4)"<br />
 Import-Package:<br />
  org.eclipse.contribution.jdt.cuprovider,<br />
  org.eclipse.contribution.jdt.imagedescriptor,<br />
Index: src/scala/tools/editor/Typers.scala<br />
===================================================================<br />
--- src/scala/tools/editor/Typers.scala	(revision 17110)<br />
+++ src/scala/tools/editor/Typers.scala	(working copy)<br />
@@ -6,7 +6,6 @@</p>
<p> package scala.tools.editor</p>
<p>-import scala.annotation.unchecked.uncheckedStable<br />
 import scala.collection.jcl._</p>
<p> import nsc.{util,io}<br />
Index: src/scala/tools/editor/TypersPresentations.scala<br />
===================================================================<br />
--- src/scala/tools/editor/TypersPresentations.scala	(revision 17110)<br />
+++ src/scala/tools/editor/TypersPresentations.scala	(working copy)<br />
@@ -6,7 +6,6 @@</p>
<p> package scala.tools.editor</p>
<p>-import scala.annotation.unchecked.uncheckedStable<br />
 import scala.collection.jcl.{LinkedHashMap,LinkedHashSet}<br />
 import scala.collection.mutable.ListBuffer</p>
<p>@@ -595,10 +594,13 @@<br />
           val str = name.decode<br />
           val key = if (sym.isMethod) str.trim+header(sym) else str.trim<br />
           val last = str.last<br />
+<br />
+          import org.eclipse.jdt.core.search.SearchPattern</p>
<p>           // TODO: check accessibility.<br />
-          if (name.isTypeName == isType &amp;&amp; str.toLowerCase.startsWith(leading.toLowerCase) &amp;&amp;<br />
-              (str.indexOf('$') == -1) &amp;&amp; last != ' ' &amp;&amp; !contains(key)) {<br />
+          if (name.isTypeName == isType &amp;&amp; (str.indexOf('$') == -1) &amp;&amp; last != ' ' &amp;&amp;<br />
+                !contains(key) &amp;&amp; (str.toLowerCase.startsWith(leading.toLowerCase) ||<br />
+                SearchPattern.camelCaseMatch(leading, str))) {<br />
             val sym0 = if (verify==null) sym else verify(sym)<br />
             if (sym0 != compiler.NoSymbol) {<br />
               val high = if (pt != null) sym0.tpe &lt;:&lt; pt<br />
</code></p>
<p>It includes my simple <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1644#comment:1">camel-case content assist patch</a>, some version restrictions and the removal of the imports for the uncheckedStable annotation since it was moved outside of the scala package in 2.8.0. The compiler and standard library are the latest version from the 2.7.x branch. I&#8217;ve done some light testing and the plugin works for me, but the usual disclaimers apply. Be prepared to have to uninstall and reinstall the plugin if things don&#8217;t work out.</p>
<p><strong>Update:</strong> I noticed that two <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1716">annoying</a> <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1717">bugs</a> were <a href="https://lampsvn.epfl.ch/trac/scala/changeset/17107">introduced</a> on Friday. I would recommend not using the current build. I will update it once they are fixed.</p>
<p><strong>Update 2:</strong> See <a href="http://blog.juma.me.uk/2009/02/18/scala-plugin-for-eclipse-snapshot-r17139/">here</a> for a newer build with fixes for the mentioned issues.</p>
<p><strong>Update 3: </strong> With the release of <a href="http://www.scala-lang.org/node/1493">Scala 2.7.4-rc1</a>, this backport is obsolete.</p>
<br />Posted in eclipse, scala Tagged: eclipse plugin, scala <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=68&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2009/02/14/scala-plugin-snapshot/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Code reuse by copy and paste</title>
		<link>http://blog.juma.me.uk/2009/02/13/code-reuse-by-copy-and-paste/</link>
		<comments>http://blog.juma.me.uk/2009/02/13/code-reuse-by-copy-and-paste/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 20:15:48 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[code reuse]]></category>
		<category><![CDATA[copy and paste]]></category>
		<category><![CDATA[scala eclipse plugin]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=60</guid>
		<description><![CDATA[I was investigating what would need to be done to implement camel-case code assist for the Scala plugin when I ran across the following gem in CharOperation (Eclipse JDT): public static final boolean camelCaseMatch(char[] pattern, int patternStart, int patternEnd, char[] name, int nameStart, int nameEnd, boolean samePartCount) { /* !!!!!!!!!! WARNING !!!!!!!!!! * The content [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=60&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I was investigating what would need to be done to implement camel-case code assist for the Scala plugin when I ran across the following gem in CharOperation (Eclipse JDT):</p>
<pre class="brush: java;">
public static final boolean camelCaseMatch(char[] pattern, int patternStart, int patternEnd, char[] name, int nameStart, int nameEnd, boolean samePartCount) {

	/* !!!!!!!!!! WARNING !!!!!!!!!!
	 * The content of this method has been fully copied to
	 * SearchPattern#camelCaseMatch(String, int, int, String, int, int, boolean).
	 *
	 * So, if current method is modified, do NOT forget to copy again its content
	 * to SearchPattern corresponding method!
	 */
</pre>
<p>And in SearchPattern:</p>
<pre class="brush: java;">
public static final boolean camelCaseMatch(String pattern, int patternStart, int patternEnd, String name, int nameStart, int nameEnd, boolean samePartCount) {

	/* !!!!!!!!!! WARNING !!!!!!!!!!
	 * The algorithm of this method has been entirely copied from
	 * CharOperation#camelCaseMatch(char[], int, int, char[], int, int, boolean).
	 * Array lengths have been replaced with call to {@link String#length()} and
	 * array direct access have been replaced with call to {@link String#charAt(int)}.
	 *
	 * So, do NOT modify this method directly to fix any bug but modify first the
	 * corresponding CharOperation method and do the copy again to be sure that
	 * these two methods are kept synchronized.
	 */
</pre>
<p>I am sure there is a reason why this was done, but how ugly&#8230;</p>
<p><strong>Update: </strong> At least JDT made it easy to implement what I <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1644#comment:1">wanted</a>.</p>
<br />Posted in eclipse, scala Tagged: code reuse, copy and paste, eclipse, scala eclipse plugin <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=60&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2009/02/13/code-reuse-by-copy-and-paste/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Objects with no allocation overhead</title>
		<link>http://blog.juma.me.uk/2008/12/17/objects-with-no-allocation-overhead/</link>
		<comments>http://blog.juma.me.uk/2008/12/17/objects-with-no-allocation-overhead/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 04:41:11 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[escape analysis]]></category>
		<category><![CDATA[scalar replacement]]></category>
		<category><![CDATA[object allocation]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=47</guid>
		<description><![CDATA[We have all heard about how HotSpot is really good at dealing with short-lived objects (both allocation and GC), but the truth is that object allocation is still pretty costly when compared to operations like addition or multiplication. Allocating an object for each step of an iteration over a large collection to make a simple [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=47&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>We have all heard about how HotSpot is really good at dealing with short-lived objects (both allocation and GC), but the truth is that object allocation is still pretty costly when compared to operations like addition or multiplication. Allocating an object for each step of an iteration over a large collection to make a simple computation might sound like the kind of thing no-one would ever do, but it&#8217;s actually quite common in languages like Scala (as described in a previous <a href="http://blog.juma.me.uk/2008/09/15/efficient-scala-with-primitive-collections/">post</a>). In Java-land, if you use the Function class from Google Collections with primitive wrappers, the same issue may occur. There are many JVM improvements that could help depending on the specific case (generic specialisation, value types, fixnums to name a few), but it&#8217;s unclear if/when we&#8217;ll get them.</p>
<p>So, what about that title? <a href="http://en.wikipedia.org/wiki/Escape_analysis">Escape analysis</a> was introduced during Java 6, but the information gathered was only used for lock elision. However, this information can also be used for other interesting optimisations like scalar replacement and stack allocation. There have been <a href="http://blogs.sun.com/fatcatair/entry/tiered_compilation_issues">doubts about the benefits of stack allocation</a> (discussed in the comments) so the focus has been on scalar replacement so that the object is never in memory. At least that&#8217;s the theory.</p>
<p>Edward Lee started a couple of threads in the Hotspot-dev mailing list about scalar replacement <a href="http://www.nabble.com/C2-Scalar-Replacement-Behavior--tt20545583.html">here</a> and <a href="http://www.nabble.com/Run-optimizations-before-Escape-Analysis--tt20808405.html">here</a> which reminded me to do some experiments. Note that this feature is still in development so the results posted here are preliminary and not indicative of how it will perform once it&#8217;s final. Still, it&#8217;s interesting to see how well it works at this time. I picked the latest JDK7 build (build 41) and ran a few tests with the following arguments passed to java &#8220;-XX:MaxPermSize=256m -Xms128m -Xmx3328m -server -XX:+UseConcMarkSweepGC&#8221; and either XX:-DoEscapeAnalysis or XX:+DoEscapeAnalysis.</p>
<p>I started by choosing the simplest test possible. Note that either testSimpleAllocation or testNoAllocation would be commented out.</p>
<pre class="brush: java;">
class C(val a: Int, val b: Int)

object Test {
  def main(args: Array[String]) {
    for (i &lt;- 1 to 10) testSimpleAllocation()
    //for (i &lt;- 1 to 10) testNoAllocation()
  }

  def testSimpleAllocation() = {
    System.gc()
    var time = System.currentTimeMillis;
    var i = 0
    var sum = 0
    while (i &lt; 1000000000) {
      sum += baz(new C(i + 1, i + 2))
      i += 1
    }
    println(sum)
    println(System.currentTimeMillis - time)
  }

  def testNoAllocation() = {
    System.gc()
    var time = System.currentTimeMillis;
    var i = 0
    var sum = 0
    while (i &lt; 1000000000) {
      sum += baz(i + 1, i + 2)
      i += 1
    }
    println(sum)
    println(System.currentTimeMillis - time)
  }

  def baz(a: Int, b: Int): Int = a + b

  def baz(c: C): Int = c.a + c.b
}
</pre>
<p>The result were:</p>
<p><code><br />
testNoAllocation: 403<br />
testSimpleAllocation with EA: 1006<br />
testSimpleAllocation without EA: 9190<br />
</code></p>
<p>As we can see, escape analysis has a tremendous effect and the method finishes in 11% of the time taken with it disabled. However, the version with no allocation is still substantially faster.</p>
<p>I decided to test a foreach method that takes a Function object next (this time in Java because it does less magic behind the scenes):</p>
<pre class="brush: java;">
package test;

public class EscapeAnalysis {

  interface Function&lt;T, R&gt; {
    R apply(T value);
  }

  interface IntProcedure {
    void apply(int value);
  }

  static class BoxedArray {
    private final int[] array;

    public BoxedArray(int length) {
      array = new int[length];
    }

    public int length() {
      return array.length;
    }

    public void foreach(Function&lt;Integer, Void&gt; function) {
      for (int i : array)
        function.apply(new Integer(i));
    }

    public void foreach(IntFunction function) {
      for (int i : array)
        function.apply(i);
    }

    public void set(int index, int value) {
      array[index] = value;
    }

    public void foreachWithAutoboxing(Function&lt;Integer, Void&gt; function) {
      for (int i : array)
        function.apply(i);
    }
  }

  public static void main(String[] args) {
    BoxedArray array = new BoxedArray(100000000);
    /* We are careful not to restrict our ints to the ones in the Integer.valueOf cache */
    for (int i = 0; i &lt; array.length(); i++)
      array.set(i, i);

    for (int i = 0; i &lt; 10; i++)
      test(array);
  }

  private static void test(BoxedArray array) {
    System.gc();
    long time = System.currentTimeMillis();
    final int[] sum = new int[] { 0 };

    /* Uncomment the one that should be executed */
    testIntegerForeach(array, sum);
//    testIntegerForeachWithAutoboxing(array, sum);
//    testIntForeach(array, sum);

    System.out.println(System.currentTimeMillis() - time);
    System.out.println(sum[0]);
  }

  private static void testIntegerForeachWithAutoboxing(BoxedArray array, final int[] sum) {
    array.foreachWithAutoboxing(new Function&lt;Integer, Void&gt;() {
      public Void apply(Integer value) {
        sum[0] += value;
        return null;
      }
    });
  }

  private static void testIntegerForeach(BoxedArray array, final int[] sum) {
    array.foreach(new Function&lt;Integer, Void&gt;() {
      public Void apply(Integer value) {
        sum[0] += value;
        return null;
      }
    });
  }

  private static void testIntForeach(BoxedArray array, final int[] sum) {
    array.foreach(new IntFunction() {
      public void apply(int value) {
        sum[0] += value;
      }
    });
  }
}
</pre>
<p>The results were:</p>
<p><code><br />
testIntForeach: 130<br />
testIntegerForeachWithAutoboxing with EA: 1064<br />
testIntegerForeach with EA: 224<br />
testIntegerForeachWithAutoboxing without EA: 1039<br />
testIntegerForeach without EA: 1024<br />
</code></p>
<p>This test shows something interesting,  EA gives no improvement if Integer.valueOf (called by auto-boxing) is used instead of new Integer. Apart from that, the results are somewhat similar to the first ones (EA provides a substantial boost, but not enough to match the specialised implementation). After quickly testing that the boxing methods in ScalaRunTime had the same effect as Integer.valueOf, I decided that it was not worth testing more complex scenarios.</p>
<p>It seems like there&#8217;s a lot of potential for scalar replacement, but HotSpot needs to do a better job at detecting cases where it can be used safely. If nothing else, at least knowledge of the valueOf methods should be hardcoded into the system. I hope that a more general solution is found though because other languages on the JVM may use different methods (as mentioned earlier Scala uses methods in ScalaRunTime instead). It will also be interesting to see if the performance can get even closer to the no allocation case. Since the feature is still in development, we can hope. :)</p>
<p><strong>Update:</strong> The early access release of <a href="https://jdk6.dev.java.net/6uNea.html">JDK 6 Update 14</a> also contains this feature.</p>
<br />Posted in java, jvm, scala, Uncategorized Tagged: escape analysis, jvm, object allocation, performance, scalar replacement <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=47&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2008/12/17/objects-with-no-allocation-overhead/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>JDK6u12, Java 7 and Devoxx</title>
		<link>http://blog.juma.me.uk/2008/12/13/jdk6u12-java-7-and-devoxx/</link>
		<comments>http://blog.juma.me.uk/2008/12/13/jdk6u12-java-7-and-devoxx/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 00:34:24 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[64-bit plugin]]></category>
		<category><![CDATA[devoxx]]></category>
		<category><![CDATA[java 7]]></category>
		<category><![CDATA[java concurrency]]></category>
		<category><![CDATA[jdk6u12]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=49</guid>
		<description><![CDATA[With JavaFX 1.0 out of the way, it seems like the Java 7 train has started moving again. Concurrency plans posted by Doug Lea. Two points of interest are that the parallel collections API is probably not going to get included (but the core fork-join framework will) and that a low-level fences API might get [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=49&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>With JavaFX 1.0 out of the way, it seems like the Java 7 train has started moving again.</p>
<p><a href="http://article.gmane.org/gmane.comp.java.jsr.166-concurrency/5602">Concurrency plans</a> posted by Doug Lea. Two points of interest are that the parallel collections API is probably not going to get included (but the core fork-join framework will) and that a low-level <a href="http://gee.cs.oswego.edu/dl/jsr166/dist/docs/java/util/concurrent/atomic/Fences.html">fences API</a> might get included. Without closures, it&#8217;s hard to include the parallel collections API with good performance for primitives while avoiding interface explosion. The positive aspect is that it will continue to be developed outside the JDK giving it more flexibility in terms of API evolution.</p>
<p><a href="http://blogs.sun.com/theplanetarium/entry/from_devoxx_javafx_on_show">Devoxx summary</a> by Danny Coward containing various links covering JavaFX, JDK7 and Languages in the JVM.</p>
<p><a href="http://hamletdarcy.blogspot.com/2008/12/java-7-update-from-mark-reinhold-at.html">Summary of Java 7 update given by Mark Reinhold</a> written by Hamlet D&#8217;Arcy. <a href="http://blogs.sun.com/darcy/entry/small_language_changes_jdk_7">Small language changes</a> and <a href="http://blogs.sun.com/mr/entry/jigsaw">Project Jigsaw</a> had already been announced and many of the items described there had been known for a while, but some new ones are Null dereference expressions, <a href="http://openjdk.java.net/projects/xrender/">XRender pipeline for Java 2D</a> and the chance of a MVM-lite. The XRender pipeline is interesting because it was developed by <a href="http://linuxhippy.blogspot.com/">Clemens Eisserer</a> as part of the OpenJDK challenge and would be a nice example of an external contribution to OpenJDK.</p>
<p>One thing that is clear from the various announcements is that Sun intends to use OpenJDK as the place where work for Java 7 will take place (even if JSRs are also planned). Some people expressed concern that this is bad because it circumvents the JCP and that OpenJDK is a project controlled by Sun since the vast majority of the committers are from Sun. Given how opaque the JCP is, I don&#8217;t see how OpenJDK could be worse, but my hope is that Sun will run these projects transparently as promised where the end-result is diversification of committers due to more external participation.</p>
<p>Finally, for the people who still use the proprietary JDK from Sun, there&#8217;s an early access release of <a href="http://blogs.sun.com/SDNProgramNews/entry/java_se_6_update_121">JDK6u12</a> that includes a 64-bit Java Plugin.</p>
<br />Posted in java, jvm Tagged: 64-bit plugin, devoxx, java 7, java concurrency, jdk6u12 <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=49&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2008/12/13/jdk6u12-java-7-and-devoxx/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Not just for academics?</title>
		<link>http://blog.juma.me.uk/2008/12/05/not-just-for-academics/</link>
		<comments>http://blog.juma.me.uk/2008/12/05/not-just-for-academics/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 22:44:30 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[jobs]]></category>

		<guid isPermaLink="false">http://blog.juma.me.uk/?p=42</guid>
		<description><![CDATA[At least ClariFI seems to think so. Paul Chiusano announced in the Scala mailing list that ClariFI is looking to hire developers &#8220;with a strong background in functional programming to do a mixture of Scala and Java programming&#8221;. The mailing list thread contains more details including a link to the official job posting. It will [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=42&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>At least <a href="http://clarifi.com/">ClariFI</a> seems to think so. Paul Chiusano <a href="http://www.nabble.com/-scala--Scala-job-in-Boston-writing-quantitative-finance-software-td20780369.html">announced</a> in the Scala mailing list that ClariFI is looking to hire developers &#8220;with a strong background in functional programming to do a mixture of Scala and Java programming&#8221;. The mailing list thread contains more details including a link to the official job posting.</p>
<p>It will be interesting to see if posts like that will become a common occurrence in the future.</p>
<br />Posted in scala Tagged: jobs, scala <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=42&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2008/12/05/not-just-for-academics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>32-bit or 64-bit JVM? How about a Hybrid?</title>
		<link>http://blog.juma.me.uk/2008/10/14/32-bit-or-64-bit-jvm-how-about-a-hybrid/</link>
		<comments>http://blog.juma.me.uk/2008/10/14/32-bit-or-64-bit-jvm-how-about-a-hybrid/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 07:07:55 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[jvm]]></category>
		<category><![CDATA[32-bit]]></category>
		<category><![CDATA[64-bit]]></category>
		<category><![CDATA[Compressed Oops]]></category>
		<category><![CDATA[hotspot]]></category>
		<category><![CDATA[memory usage]]></category>

		<guid isPermaLink="false">http://ijuma.wordpress.com/?p=32</guid>
		<description><![CDATA[Before x86-64 came along, the decision on whether to use 32-bit or 64-bit mode for architectures that supported both was relatively simple: use 64-bit mode if the application requires the larger address space, 32-bit mode otherwise. After all, no point in reducing the amount of data that fits into the processor cache while increasing memory [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=32&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Before <a href="http://en.wikipedia.org/wiki/X86-64">x86-64</a> came along, the decision on whether to use 32-bit or 64-bit mode for architectures that supported both was relatively simple: use 64-bit mode if the application requires the larger address space, 32-bit mode otherwise. After all, no point in reducing the amount of data that fits into the processor cache while increasing memory usage and bandwidth if the application doesn&#8217;t need the extra addressing space.</p>
<p>When it comes to x86-64, however, there&#8217;s also the fact that the number of named general-purpose registers has doubled from 8 to 16 in 64-bit mode. For CPU intensive apps, this may mean performance at the cost of extra memory usage. On the other hand, for memory intensive apps 32-bit mode might be better in if you manage to fit your application within the address space provided. Wouldn&#8217;t it be nice if there was a single JVM that would cover the common cases?</p>
<p>It turns out that the HotSpot engineers have been working on doing just that through a feature called <a href="http://wikis.sun.com/display/HotSpotInternals/CompressedOops">Compressed oops</a>. The benefits:</p>
<ul>
<li>Heaps up to 32GB (instead of the theoretical 4GB in 32-bit that in practice is closer to 3GB)</li>
<li>64-bit mode so we get to use the extra registers</li>
<li>Managed pointers (including Java references) are 32-bit so we don&#8217;t waste memory or cache space</li>
</ul>
<p>The main disadvantage is that encoding and decoding is required to translate from/to native addresses. HotSpot tries to avoid these operations as much as possible and they are relatively cheap. The hope is that the extra registers give enough of a boost to offset the extra cost introduced by the encoding/decoding.</p>
<p>Compressed Oops have been included (but disabled by default) in the performance release <a href="http://java.sun.com/javase/technologies/performance.jsp">JDK6u6p</a> (requires you to fill a survey), so I decided to try it in an internal application and compare it with 64-bit mode and 32-bit mode.</p>
<p>The tested application has two phases, a single threaded one followed by a multi-threaded one. Both phases do a large amount of allocation so memory bandwidth is very important. All tests were done on a dual quad-core Xeon 5400 series with 10GB of RAM. I should note that a different JDK version had to be used for 32-bit mode (JDK6u10rc2) because there is no Linux x86 build of JDK6u6p. I chose the largest heap size that would allow the 32-bit JVM to run the benchmark to completion without crashing.</p>
<p>I started by running the application with a smaller dataset:</p>
<blockquote><p>
<strong>JDK6u10rc2 32-bit</strong><br />
Single-threaded phase: 6298ms<br />
Multi-threaded phase (8 threads on 8 cores): 17043ms<br />
Used Heap after full GC: 430MB<br />
JVM Args: -XX:MaxPermSize=256m -Xms3328m -Xmx3328m -server -XX:+UseConcMarkSweepGC
</p></blockquote>
<blockquote><p>
<strong>JDK6u6p 64-bit with Compressed Oops</strong><br />
Single-threaded phase: 6345<br />
Multi-threaded phase (8 threads on 8 cores): 16348<br />
Used Heap after full GC: 500MB<br />
JVM Args: -XX:MaxPermSize=256m -Xms3328m -Xmx3328m -server -XX:+UseConcMarkSweepGC -XX:+UseCompressedOops
</p></blockquote>
<p>The performance numbers are similar and the memory usage of the 64-bit JVM with Compressed Oops is 16% larger.</p>
<blockquote><p>
<strong>JDK6u6p 64-bit</strong><br />
Single-threaded phase: 6463<br />
Multi-threaded phase (8 threads on 8 cores): 18778<br />
Used Heap after full GC: 700MB<br />
JVM Args: -XX:MaxPermSize=256m -Xms3328m -Xmx3328m -server -XX:+UseConcMarkSweepGC
</p></blockquote>
<p>The performance is again similar, but the memory usage of the 64-bit JVM is much higher, over 60% higher than the 32-bit JVM one.</p>
<p>Let&#8217;s try the larger dataset now:</p>
<blockquote><p>
<strong>JDK6u10rc2 32-bit</strong><br />
Single-threaded phase: 14188ms<br />
Multi-threaded phase (8 threads on 8 cores): 73451ms<br />
Used Heap after full GC: 1.25GB<br />
JVM Args: -XX:MaxPermSize=256m -Xms3328m -Xmx3328m -server -XX:+UseConcMarkSweepGC
</p></blockquote>
<blockquote><p>
<strong>JDK6u6p 64-bit with CompressedOops</strong><br />
Single-threaded phase: 13742<br />
Multi-threaded phase (8 threads on 8 cores): 76664ms<br />
Used Heap after full GC: 1.45GB<br />
JVM Args: -XX:MaxPermSize=256m -Xms3328m -Xmx3328m -server -XX:+UseConcMarkSweepGC -XX:+UseCompressedOops
</p></blockquote>
<p>The performance difference and memory overhead are the same as with the smaller dataset. The benefit of Compressed Oops here is that we still have plenty of headroom while the 32-bit JVM is getting closer to its limits. This may not be apparent from the heap size after a full GC, but during the multi-threaded phase the peak memory usage is quite a bit larger and the fact that the allocation rate is high does not help. This becomes more obvious when we look at the results for the 64-bit JVM.</p>
<blockquote><p>
<strong>JDK6u6p 64-bit</strong><br />
Single-threaded phase: 14610<br />
Multi-threaded phase (8 threads on 8 cores): 104992<br />
Used Heap after full GC: 2GB<br />
JVM Args: -XX:MaxPermSize=256m -Xms4224m -Xmx4224m -server -XX:+UseConcMarkSweepGC
</p></blockquote>
<p>I had to increase the Xms/Xmx to 4224m for the application to run to completion. Even so, the performance of the multi-threaded phase took a substantial performance hit when compared to the other two JVM configurations. All in all, the 64-bit JVM without compressed oops does not do well here.</p>
<p>In conclusion, it seems that compressed oops is a feature with a lot of promise and it allows the 64-bit JVM to be competitive even in cases that favour the 32-bit JVM. It might be interesting to test applications with different characteristics to compare the results. It&#8217;s also worth mentioning that since this is a new feature, it&#8217;s possible that performance will improve further before it&#8217;s integrated into the normal JDK releases. As it is though, it already hits a sweet spot and if it weren&#8217;t for the potential for instability, I would be ready to ditch my 32-bit JVM.</p>
<p><strong>Update:</strong> The early access release of <a href="https://jdk6.dev.java.net/6uNea.html">JDK 6 Update 14</a> also contains this feature.</p>
<br />Posted in jvm Tagged: 32-bit, 64-bit, Compressed Oops, hotspot, jvm, memory usage <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=32&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2008/10/14/32-bit-or-64-bit-jvm-how-about-a-hybrid/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Local variables scope in HotSpot</title>
		<link>http://blog.juma.me.uk/2008/10/11/local-variables-scope-in-hotspot/</link>
		<comments>http://blog.juma.me.uk/2008/10/11/local-variables-scope-in-hotspot/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 06:16:26 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[jvm]]></category>
		<category><![CDATA[garbage collection]]></category>
		<category><![CDATA[hotspot]]></category>
		<category><![CDATA[jit]]></category>

		<guid isPermaLink="false">http://ijuma.wordpress.com/?p=30</guid>
		<description><![CDATA[Assume the following code: public void foo() { C c = new C(); bar(c.baz); // assume that baz does not reference c } I was under the impression that HotSpot would not garbage collect c before the local variable went out of scope although it is legally allowed to do so. I even heard of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=30&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Assume the following code:</p>
<pre class="brush: java;">
  public void foo() {
    C c = new C();
    bar(c.baz); // assume that baz does not reference c
  }
</pre>
<p>I was under the impression that HotSpot would not garbage collect c before the local variable went out of scope although it is legally allowed to do so. I even heard of issues where unnecessary garbage was retained as a result (usual workarounds are to null the variable or to inline it).</p>
<p>According to this <a href="http://bugs.sun.com/view_bug.do?bug_id=6721588">bug report</a> (Server JIT optimization can cause objects to go out of scope prematurely), the Server VM is actually able to GC the object before the local variable goes out of scope. It would be interesting to know if it can detect such cases reliably.</p>
<br />Posted in jvm Tagged: garbage collection, hotspot, jit, jvm <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=30&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2008/10/11/local-variables-scope-in-hotspot/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>AOT and JVM</title>
		<link>http://blog.juma.me.uk/2008/10/08/aot-for-java/</link>
		<comments>http://blog.juma.me.uk/2008/10/08/aot-for-java/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 16:21:07 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[jvm]]></category>
		<category><![CDATA[aot]]></category>
		<category><![CDATA[ibm]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jit]]></category>
		<category><![CDATA[memory sharing]]></category>
		<category><![CDATA[start-up performance]]></category>

		<guid isPermaLink="false">http://ijuma.wordpress.com/?p=27</guid>
		<description><![CDATA[There have been a few AOT compilers for Java for some time. Two of the better known examples are GCJ and Excelsior JET. Even though Excelsior JET also has a JIT, the main focus was on the AOT aspect. There have been many suggestions that HotSpot should cache the JIT-generated code to improve start-up performance, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=27&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>There have been a few <a href="http://en.wikipedia.org/wiki/AOT_compiler">AOT</a> compilers for Java for some time. Two of the better known examples are <a href="http://gcc.gnu.org/java/">GCJ</a> and <a href="http://www.excelsior-usa.com/jet.html">Excelsior JET</a>. Even though Excelsior JET also has a JIT, the main focus was on the AOT aspect.</p>
<p>There have been many suggestions that HotSpot should cache the JIT-generated code to improve start-up performance, avoid the need for a warm-up phase on every invocation of the application and possibly share more data between applications. This is particularly relevant for desktop applications. HotSpot engineers claim that this is a complex task and that the benefits might not be as great as expected because AOT-generated code would be slower than JIT-generated one, so they implemented a simpler solution in JDK 5, <a href="http://java.sun.com/j2se/1.5.0/docs/guide/vm/class-data-sharing.html">Class Data Sharing</a>. It&#8217;s pretty limited because it only works with the Client VM and the serial garbage collector and also because it only loads a set of classes from the system jar.</p>
<p>Interestingly, IBM did some work in this area in the IBM JRE for Java 5 and improved it further in the one for Java 6. This is described in some detail in a <a href="http://www.ibm.com/developerworks/library/j-sharedclasses/">developerWorks article</a>. It&#8217;s worth reading if you&#8217;re interested in this sort of thing, but I&#8217;ll list some points that I found interesting:</p>
<ul>
<li>AOT code can be stored into a shared class cache allowing another JVM to use it to reduce startup time.</li>
<li>Class compression is used to increase the amount of classes that are stored in the cache.</li>
<li>AOT code is also subject to JIT compilation if it&#8217;s invoked often in order to optimise it further.</li>
<li>AOT code executed by a JVM is copied from the shared class cache so there is no direct footprint benefit but there are memory and CPU savings from being able to reuse this code rather than repeat the compilation.
<li>AOT compilation is based on heuristics that select methods that are likely to improve startup time.</li>
<li>Eclipse without any additional plugins took 3.313 to start with AOT and shared classes versus 4.204 seconds without. Larger improvements could take place if there were more plugins installed.</li>
<li>Tomcat startup time improved from 1138ms to 851ms. Using shared classes without AOT caused the time to be 950ms, which means that both AOT and shared classes contributed to the improvement.</li>
</ul>
<p>Downloading the IBM JRE/JDK requires registration and in case you need the Windows version, you must download a bundle that includes Eclipse. Links to the various downloads can be found in the developerWorks article.</p>
<p>These are interesting results, and it would be interesting to find out if HotSpot would also benefit from similar enhancements.</p>
<br />Posted in jvm Tagged: aot, ibm, java, jit, jvm, memory sharing, start-up performance <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=27&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2008/10/08/aot-for-java/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Scala in the JVM Languages Summit</title>
		<link>http://blog.juma.me.uk/2008/09/30/scala-in-the-jvm-languages-summit/</link>
		<comments>http://blog.juma.me.uk/2008/09/30/scala-in-the-jvm-languages-summit/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 05:24:06 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[jvm languages summit]]></category>

		<guid isPermaLink="false">http://ijuma.wordpress.com/?p=21</guid>
		<description><![CDATA[Since I&#8217;ve seen no mention of this in Planet Scala (although it was discussed in #scala), here are some Scala-related links from the JVM Languages summit: Optimizing Higher-Order Functions in Scala by Iulian Dragos. I haven&#8217;t tried the various optimisation flags in scalac yet, but I am curious if they will have any effect in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=21&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;ve seen no mention of this in <a href="http://www.drmaciver.com/planetscala/">Planet Scala</a> (although it was discussed in #scala), here are some Scala-related links from the JVM Languages summit:</p>
<ul>
<li><a href="http://wiki.jvmlangsummit.com/ScalaOptimization">Optimizing Higher-Order Functions in Scala</a> by <a href="http://lamp.epfl.ch/~dragos">Iulian Dragos</a>. I haven&#8217;t tried the various optimisation flags in scalac yet, but I am curious if they will have any effect in the primitive collections with scala benchmark from a previous <a href="http://ijuma.wordpress.com/2008/09/15/efficient-scala-with-primitive-collections/">blog entry</a>. These flags have been a bit buggy in the past, but hopefully recent fixes have solved the problems.</li>
<li><a href="http://wiki.jvmlangsummit.com/Scalify">Scalify: Automatic translation from Java to Scala</a> by <a href="http://www.improving.org/paulp/">Paul Phillips</a>. This tool looks very interesting because the approach used is a lot more sophisticated than <a href="http://code.google.com/p/jatran/">jatran</a>. I have been meaning to take a look at it, but all of my code uses generics and it doesn&#8217;t support that yet.</li>
<li><a href="http://blogs.azulsystems.com/cliff/2008/09/jvm-language-su.html">Cliff Click&#8217;s post-Summit blog entry</a>. It includes a link to the <a href="http://wiki.jvmlangsummit.com/pdf/36_Click_fastbcs.pdf">slides</a> for his talk, &#8220;Fast Bytecodes for Funny Languages&#8221;. Scala is one of the languages covered (although very briefly) with the results coming from the translation of a simple Java micro-benchmark to Scala available <a href="http://blogs.azulsystems.com/cliff/2008/09/a-plea-for-prog.html">here</a> (in the comments). As expected, Scala can generate bytecode that is pretty much the same as Java if low-level constructs are used, but the performance suffers quite a bit if idiomatic Scala is used while dealing with primitives (at least with the default compilation flags).</li>
</ul>
<p>For more general coverage of the summit:</p>
<ul>
<li><a href="http://www.javaposse.com/index.php?post_id=385201">Java Posse #208 &#8211; Report from JVM Languages Summit</a></li>
<li><a href="http://wiki.jvmlangsummit.com/">JVM Languages Summit Wiki</a></li>
</ul>
<p><a href="http://rickyclarkson.blogspot.com/">Ricky Clarkson</a> mentioned on IRC that videos of the talks will be made available on InfoQ and Google Video.</p>
<p><strong>Update:</strong> John Rose&#8217;s <a href="http://blogs.sun.com/jrose/entry/view_from_the_summit">post-summit blog entry</a> is a nice round-up. </p>
<br />Posted in scala Tagged: jvm languages summit, scala <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=21&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2008/09/30/scala-in-the-jvm-languages-summit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>HotSpot JIT &#8220;Optimization&#8221;</title>
		<link>http://blog.juma.me.uk/2008/09/27/hotspot-jit-optimization/</link>
		<comments>http://blog.juma.me.uk/2008/09/27/hotspot-jit-optimization/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 01:05:16 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[hotspot]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jit]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[microbenchmarks]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://ijuma.wordpress.com/?p=18</guid>
		<description><![CDATA[I noticed Scala ticket #1377 the other day. Even though I think the bug is valid, it&#8217;s for different reasons to the ones supplied by the reporter. I had my doubts that the casts would have any measurable cost and the informal benchmark provided looked suspect. This is all described in the ticket, so I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=18&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I noticed Scala ticket <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1377">#1377</a> the other day. Even though I think the bug is valid, it&#8217;s for different reasons to the ones supplied by the reporter. I had my doubts that the casts would have any measurable cost and the informal benchmark provided looked suspect. This is all described in the ticket, so I won&#8217;t go over it again here. The point of this blog is some weird behaviour I noticed in my version of the benchmark.</p>
<p>The benchmark looks like:</p>
<pre class="brush: java;">
  def f(i: Iterator[_]) = i.hasNext

  def main(args: Array[String]) {
    test()
  }

  def test() {
    var i = 0
    while (i &lt; 10) {
      val time = System.currentTimeMillis
      val result = inner()
      i += 1
      println(&quot;Time: &quot; + (System.currentTimeMillis - time))
      println(&quot;Value: &quot; + result)
    }
  }

  def inner() = {
    //val empty = Iterator.empty // checkcast occurs within loop
    val empty: Iterator[_] = Iterator.empty // checkcast outside loop
    var i = 0L
    while (i &lt; 10000000000L) {
      f(empty)
      i += 1
    }
    i
  }
}
</pre>
<p>According to this version of the benchmark the extra casts don&#8217;t cause any performance difference, so I will just focus on the one without the extra casts. The results with JDK 6 Update 10 RC1 64-bit were:</p>
<blockquote><p>
Time: 4903<br />
Time: 4883<br />
Time: 7213<br />
Time: 7197<br />
Time: 7203<br />
Time: 7212<br />
Time: 7185<br />
Time: 7190<br />
Time: 7210<br />
Time: 7188
</p></blockquote>
<p>That is odd. Instead of getting faster, the benchmark gets slower from the third iteration onwards. With JITs like these, we&#8217;re better off with interpreters. ;) Ok, that&#8217;s an exaggeration but let&#8217;s investigate this further.</p>
<p>Before we do so, I should clarify two things. The ones paying attention might wonder where the &#8220;Value&#8221; output went. The purpose of that is just to make sure HotSpot does not optimize the inner loop away, so I trimmed it from the output. The second point is that the usage of a 64-bit JVM is important because the problem does not occur on the 32-bit version of HotSpot. I initially used the 64-bit version because it&#8217;s much faster when performing operations on longs and I had to use a long index in the loop to allow the benchmark to take a reasonable amount of time.</p>
<p>Ok, so first step is to re-run the benchmark with -Xbatch and -XX:+PrintCompilation. The results of that were:</p>
<blockquote><p>
  1   b   test.PerfTest$::f (7 bytes)<br />
  2   b   scala.Iterator$$anon$5::hasNext (2 bytes)<br />
  1%  b   test.PerfTest$::inner @ 12 (35 bytes)<br />
Time: 4938<br />
  3   b   test.PerfTest$::inner (35 bytes)<br />
Time: 4861<br />
Time: 7197<br />
Time: 7199<br />
Time: 7241</p>
</blockquote>
<p>Ok, so it seems like the inner loop got JIT&#8217;d a second time and that made it slower than the previous version, which sounds like a bug. I converted the code into Java and it turns out that we don&#8217;t need much more than a loop in the inner method to reproduce the problem:</p>
<pre class="brush: java;">
static long inner() {
  long i = 0L;
  for (; i &lt; 10000000000L; ++i);
  return i;
}
</pre>
<p>Before reporting the bug to Sun, I was curious if -XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation would give any interesting information. I pasted some parts that someone that is not a HotSpot engineer might understand with the help of <a href="http://wikis.sun.com/display/HotSpotInternals/LogCompilation+overview">this</a>.</p>
<pre class="brush: xml;">
&lt;nmethod compile_id='1' compile_kind='osr' compiler='C2' entry='0x000000002ee0d000' size='520' address='0x000000002ee0ced0' relocation_offset='264' code_offset='304' stub_offset='400' consts_offset='420' scopes_data_offset='424' scopes_pcs_offset='456' dependencies_offset='504' oops_offset='512' method='test/PerfTest inner ()J' bytes='19' count='1' backedge_count='14563' iicount='1' stamp='0.054'/&gt;
&lt;writer thread='12933456'/&gt;
&lt;task_queued compile_id='1' method='test/PerfTest inner ()J' bytes='19' count='2' backedge_count='5000' iicount='2' blocking='1' stamp='4.965' comment='count' hot_count='2'/&gt;
&lt;writer thread='43477328'/&gt;
  1   b   test.PerfTest::inner (19 bytes)
&lt;nmethod compile_id='1' compiler='C2' entry='0x000000002ee0d240' size='488' address='0x000000002ee0d110' relocation_offset='264' code_offset='304' stub_offset='368' consts_offset='388' scopes_data_offset='392' scopes_pcs_offset='424' dependencies_offset='472' oops_offset='480' method='test/PerfTest inner ()J' bytes='19' count='2' backedge_count='5000' iicount='2' stamp='4.966'/&gt;
&lt;...&gt;

&lt;task compile_id='1' compile_kind='osr' method='test/PerfTest inner ()J' bytes='19' count='1' backedge_count='14563' iicount='1' osr_bci='5' blocking='1' stamp='0.050'&gt;
&lt;...&gt;
&lt;task_done success='1' nmsize='120' count='1' backedge_count='14563' stamp='0.054'/&gt;

&lt;task compile_id='1' method='test/PerfTest inner ()J' bytes='19' count='2' backedge_count='5000' iicount='2' blocking='1' stamp='4.965'&gt;
&lt;...&gt;
&lt;task_done success='1' nmsize='88' count='2' backedge_count='5000' stamp='4.966'/&gt;
</pre>
<p>So, it seems like the inner method was first JIT&#8217;d through on-stack-replacement (i.e. OSR). Usually, on-stack-replacement does not produce the best code, so HotSpot recompiles the method again once it gets the chance. Unfortunately, it generates slower code for some reason even though the compiled method size is smaller (88 instead of 120).</p>
<p>We could go deeper in this investigation by using a debug JVM like Kohsuke Kawaguchi did <a href="http://weblogs.java.net/blog/kohsuke/archive/2008/03/deep_dive_into.html">here</a>, but I decided to just file a bug and let the HotSpot engineers handle it. :) I will update the blog once a bug number is assigned (I wonder when Sun is going to fix their bug database so that the bug id becomes available after submission of a bug&#8230;).</p>
<p><b>Update:</b> The <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6763452">bug</a> is now available in the Sun database.</p>
<br />Posted in programming, scala Tagged: hotspot, java, jit, jvm, microbenchmarks, optimization, scala <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=18&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2008/09/27/hotspot-jit-optimization/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Array variance and method overloading</title>
		<link>http://blog.juma.me.uk/2008/09/21/array-variance-and-method-overloading/</link>
		<comments>http://blog.juma.me.uk/2008/09/21/array-variance-and-method-overloading/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 04:34:09 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[array variance]]></category>
		<category><![CDATA[jatran]]></category>
		<category><![CDATA[java to scala translation]]></category>
		<category><![CDATA[method overloading]]></category>

		<guid isPermaLink="false">http://ijuma.wordpress.com/?p=16</guid>
		<description><![CDATA[One of these days I used jatran to translate the code for a simple Swing application from Java to Scala. Jatran&#8217;s translation had a few issues (some of which have been fixed since I tried it) so there were quite a few compiler errors after it finished. I fixed them and launched the application. It [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=16&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>One of these days I used <a href="http://code.google.com/p/jatran/">jatran</a> to translate the code for a simple Swing application from Java to Scala. Jatran&#8217;s translation had a few issues (some of which have been fixed since I tried it) so there were quite a few compiler errors after it finished. I fixed them and launched the application.</p>
<p>It was at this point that I noticed a change in behaviour and it was not clear why it was happening. After some investigation, it turned out that it was caused by the fact that variance of arrays in Scala is different from Java combined with poor usage of method overloading.</p>
<p>TreePath has two constructors that do different things, but one of them takes a supertype of the other:</p>
<pre class="brush: java;">
public TreePath(Object[] path)
</pre>
<pre class="brush: java;">
public TreePath(Object singlePath)
</pre>
<p>Because arrays are nonvariant in Scala, it means that scalac chooses the constructor that takes an Object for the following code:</p>
<pre class="brush: java;">
def pathToRoot: Array[TreeNode] = ...
val treePath = new TreePath(pathToRoot)
</pre>
<p>On the other hand, arrays are covariant in Java so the constructor that takes an Object[] is chosen by javac for the equivalent Java code. One way to force scalac to choose the correct constructor is to cast the result of pathToRoot:</p>
<pre class="brush: java;">
def pathToRoot: Array[TreeNode] = ...
val treePath = new TreePath(pathToRoot.asInstanceOf[Array[AnyRef]])
</pre>
<p>It&#8217;s a subtle issue that may affect other people automatically converting Java code to Scala, so I thought I&#8217;d bring it up in case it saves them some time. :)</p>
<br />Posted in scala Tagged: array variance, jatran, java to scala translation, method overloading, scala <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=16&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2008/09/21/array-variance-and-method-overloading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
		<item>
		<title>Efficient Scala with Primitive Collections</title>
		<link>http://blog.juma.me.uk/2008/09/15/efficient-scala-with-primitive-collections/</link>
		<comments>http://blog.juma.me.uk/2008/09/15/efficient-scala-with-primitive-collections/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 23:25:48 +0000</pubDate>
		<dc:creator>Ismael Juma</dc:creator>
				<category><![CDATA[scala]]></category>
		<category><![CDATA[boxing]]></category>
		<category><![CDATA[compiler hacking]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[primitive collections]]></category>
		<category><![CDATA[trove]]></category>

		<guid isPermaLink="false">http://ijuma.wordpress.com/?p=4</guid>
		<description><![CDATA[When dealing with large collections of primitives in Java/Scala, one can achieve substantial memory savings by using something like GNU Trove. Performance should also be better, but the difference may be small if the boxing does not happen in the performance-sensitive parts of the application. Using Trove is not as seamless as it should be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=4&subd=ijuma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>When dealing with large collections of primitives in Java/Scala, one can achieve substantial memory savings by using something like <a href="http://trove4j.sourceforge.net/">GNU Trove</a>. Performance should also be better, but the difference may be small if the boxing does not happen in the performance-sensitive parts of the application. Using Trove is not as seamless as it should be because its collections don&#8217;t implement java.util interfaces (there are decorators, but they cause a lot of boxing defeating the purpose of using Trove in the first place). However, the advantages outweigh the disadvantages in some cases.</p>
<p>I wanted to use Trove collections from Scala conveniently without losing the efficiency benefits. Convenience in this case means the ability to pass anonymous functions to the usual suspects (i.e. map, flatMap, filter, etc.). One would ordinarily just write a wrapper, sprinkle some implicits and that would be it. Unfortunately, a naive wrapper will not meet the efficiency requirements.</p>
<p>Let&#8217;s start with the implementation that relies on an anonymous inner class to work out the baseline performance we&#8217;re aiming at. A simple implementation that serves the purpose is a method that sums all the elements of a TIntArrayList and returns it (preventing HotSpot from optimising it out).</p>
<pre class="brush: java;">
  private def sumWithInnerClass(list: TIntArrayList): Int = {
    var sum = 0
    val p = new TIntProcedure() {
      def execute(i: Int) = {
        sum += i
        true
      }
    }
    list.forEach(p)
    sum
  }
</pre>
<p>This code is not much better than the Java equivalent (if at all), but it performs quite well. After a few iterations to allow the JVM to warm-up, it takes about 120ms to sum a list with 100 million items.</p>
<p>Let&#8217;s try a more convenient version of the code:</p>
<pre class="brush: java;">
  implicit def toIntProcedureWithBoxing(f: Int =&gt; Unit): TIntProcedure = new TIntProcedure() {
    def execute(i: Int) = {
      f(i)
      true
    }
  }

  private def sumWithFunctionAndBoxing(list: TIntArrayList): Int = {
    var sum = 0
    list.forEach{x:Int =&gt; sum += x}
    sum
  }
</pre>
<p>We define an implicit from Int =&gt; Unit (which really means Function1[Int, Unit]) to a TIntProcedure and that allows us to pass an anonymous function to forEach. For the record, I am aware that a fold would have been a nicer way to define the sum (no need for the var), but I wanted to keep it similar to the initial version since I was interested in the performance difference caused by the wrapper. The results were certainly not encouraging, the boxing caused by calling Function1[Int, Unit] from TIntProcedure resulted in performance over 10 times worse: 1300ms on average.</p>
<p>That is not acceptable, so we need a way to avoid the boxing. Fortunately, the anonymous function for Function[Int, Unit] actually defines an apply(i: Int) method&#8230; but unfortunately we have no way to cast to the anonymous inner class generated by the Scala compiler, so we can&#8217;t invoke it. A possible solution is to generate traits like the following for the primitive types we care about and have the anonymous functions implement them when appropriate.</p>
<pre class="brush: java;">
trait IntFunction[+R] extends Function1[Int, R] {
  def apply(i: Int): R
}
</pre>
<p>This gets more complicated once you consider that a function can take up to 22 parameters, but let&#8217;s for now assume that we only care about the case we use in our benchmark. I tried to think of ways to achieve this and it seemed like some compiler hacking was required. Given all my experience hacking compilers (read: none), I thought &#8220;why not?&#8221;.</p>
<p>To make my life easier, I decided not to read any documentation (not even sure if there&#8217;s any ;)) and settled for browsing and grep&#8217;ing the sources. Not too long after, I found what I was looking for, UncurryTransformer.tranform. After some analysis, it seemed like all that was needed was a conditional like:</p>
<pre class="brush: java;">
        if (formals.head == IntClass.tpe &amp;&amp; restpe == UnitClass.tpe) {
          anonClass setInfo ClassInfoType(
            List(ObjectClass.tpe, IntFunctionClass.tpe, fun.tpe, ScalaObjectClass.tpe), newScope, anonClass);
        }
</pre>
<p>Ok, I lie. I also defined IntFunctionClass in Definitions.scala. This is probably obvious, but I will mention it anyway, this is not a complete or general solution and it has a few limitations. However, it&#8217;s good enough to continue with the next part of the experiment. We can now define the following:</p>
<pre class="brush: java;">
  implicit def toIntProcedure(f: Int =&gt; Unit): TIntProcedure = new TIntProcedure() {
    def execute(i: Int) = {
      f.asInstanceOf[IntFunction[_]](i)
      true
    }
  }

  private def sumWithFunction(list: TIntArrayList): Int = {
    var sum = 0
    list.forEach{x: Int =&gt; sum += x}
    sum
  }
</pre>
<p>We cast to IntFunction before calling apply, avoiding the boxing of the int. The performance for this was around 120ms to sum 100 million ints, which is about the same as the initial version. It seems like HotSpot does a very good job of inlining, so the additional indirection is basically free.</p>
<p>Ok, so the hack works. It&#8217;s relatively ugly, but at least the cast is encapsulated in the implicit converter and during normal usage, one does not have to deal with it. With more changes to the compiler, I believe it would be possible for Int =&gt; Unit to translate to IntFunction[Unit] or even IntUnitFunction instead of Function1[Int, Unit] and the cast would then not be needed. There are certainly some issues that would have to be worked out, but there are some nice performance benefits too.</p>
<p>It would solve issues like <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1297">#1297</a> (where Range is 25 times slower than the while loop _after_ the fix) and mitigate <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1338">#1338</a>. It&#8217;s worth noting that work on scalar replacement through escape analysis in HotSpot and optimisation phases for the Scala compiler may reduce the amount of boxing that takes place, reducing the problem shown here. It&#8217;s unclear to what extent until we can try them out though.</p>
<p>The benchmark code can be found <a href="http://github.com/ijuma/misc/tree/master/scala/bench/PrimitiveBenchmarks.scala">here</a>. For my tests, I used JDK 6 Update 10 rc1 on an 8 core Mac Pro with the following options:</p>
<p>-XX:MaxPermSize=256m -Xms192m -Xmx2560m -server -XX:+UseConcMarkSweepGC</p>
<p>I think that&#8217;s enough for a first blog entry. Until next time. :)</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ijuma.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ijuma.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijuma.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijuma.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijuma.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijuma.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijuma.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijuma.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijuma.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijuma.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijuma.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijuma.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.juma.me.uk&blog=4860094&post=4&subd=ijuma&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.juma.me.uk/2008/09/15/efficient-scala-with-primitive-collections/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0eb053bf15b0a3669c973bc50be45a7c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ijuma</media:title>
		</media:content>
	</item>
	</channel>
</rss>