Traveling the road from Idea all the way to OpenJDK

The Tower Bridge on the River Thames, London in May 2013

Starting with an Idea

In May 2013, I was in traveling on business in London. The GS Collections library had been released to open source on GitHub a year and a half earlier (January 2012). I was a member of the JSR 335 Expert Group, and would post in the lambda-lib-spec-experts mail list when I wanted to share an opinion on a topic being discussed.

See Something

While I was in London, I was actively testing GS Collections with the Java Stream library using a binary snapshot of the pre-Java 8 release. I recall spending several hours in my hotel room, across from St. Paul’s Cathedral, puzzling over a peculiar performance difference I was seeing between stream and parallelStream when used with GS Collections’ FastList class.

My hotel in London, May 2013
Filtering 1,000,000 element FastList using stream, parallelStream and GSC eager — Smaller is Better
Filtering 1,000,000 element ArrayList using stream, parallelStream and GSC eager methods — Smaller is Better

Say Something

The problem seemed to center around the default implementation of spliterator on Collection that was returning an IteratorSpliterator. ArrayList returns a specialized spliterator implementation called ArrayListSpliterator. There was no spliterator provided for non-JDK RandomAccess List implementations, like FastList. I would propose in the following thread that a RandomAccessSpliterator should be added to the JDK, so non-JDK RandomAccess List implementations would not suffer significant performance penalties when using parallelStream. I reported my findings in the lambda-lib-spec-experts group mailing list. Prior to Java 8, this was the group to communicate anything around Java Streams. The following link shows the thread I started in the mail list the week that I was in London running my tests.

An unexpected detour and a very thoughtful gift

A week before I was going to go to JVMLS 2013, my wife was admitted to the hospital and diagnosed with AML (Leukemia). I wrote about this story for the first time a couple of years ago.

JVMLS 2013 Thermos

Another detour — Eclipse Collections

After Java 8 was released in March 2014, I decided after many discussions that the best path forward for GS Collections was to move to the Eclipse Foundation, where it would become Eclipse Collections. The actual migration work for Eclipse Collections was completed by Hiroshi who would become the first Eclipse Collections Project Lead. Hiroshi Ito is also one of the heroes in this story of RandomAccessSpliterator.

Me and Hiroshi Ito at JavaOne 2015 in San Francisco, where we would present Eclipse Collections by Example

Prove Something

Once Eclipse Collections was migrated to the Eclipse Foundation at the end of 2015, I finally revisited my idea from two years prior. I set out to reconfirm my concerns of the parallel performance of Java Streams with FastList. The initial release of Eclipse Collections 7.0 was feature identical to GS Collections 7.0. Eclipse Collections 7.0 and GS Collections 7.0 were both compiled with Java 7. This would mean neither library would have overrides for stream(), parallelStream() or spliterator() and would inherit any default implementations from Collection and List. The default implementation of spliterator() was still IteratorSpliterator in Java 8. IteratorSpliterator was woefully suboptimal for parallelStream for List implementations that were RandomAccess.

Filtering 1,000,000 elements from ArrayList/FastList using stream/parallelStream — Bigger is Better
Filtering 1,000,000 elements from ArrayList/FastList using stream/parallelStream — Bigger is Better

Onward to OpenJDK

Do Something

This was the initial email with patch sent to the core-libs-dev mail group by Hiroshi Ito. The email was dated May 11, 2016 which was three years and two days after I originally shared the idea with the lambda-lib-spec-experts mail group.

Java 9 and RandomAccessSpliterator

The RandomAccessSpliterator code was delivered in time to be released with Java 9 (September 2017). RandomAccessSpliterator would become the default spliterator for FastList and any other non-JDK RandomAccess List in any other library, that did not provide their own spliterator implementation.

The Long Wait

While RandomAccessSpliterator made it in time for Java 9, many companies will have waited for Java 11 before they would have seen any benefits of the optimization. It’s only been fairly recently that a large number of applications have made the migration effort from Java 8 to Java 11 or Java 17.

Filtering evens from a 1,000,000 element list using stream / parallelStream — Bigger is Better

Reflections on a road less traveled

Be prepared

Proposing and getting a change into the OpenJDK requires a serious commitment of patience, time and effort. This story demonstrates that it is entirely possible to contribute to the OpenJDK, but may not be on the timeframe you would expect. I’ve also had ideas rejected several times. It’s not personal. The JDK is used by millions of developers for over a quarter century to write and run millions of applications. The developers maintaining this amazing code base are experts and we should be careful not to waste their time.

Many ideas don’t make it, and that is perfectly okay

Here is an example of an idea that I proposed, that has not been implemented yet, and may never be, as it may just not be practical or worth the cost. The developer who responded to my initial proposal, Claes Redestad, was extremely thoughtful and helpful in his responses in the mail list. He even built a proof of concept of the method in a pull request with some benchmarks. I am very thankful for the time he took to look into my idea.

Start small and stay focused

My recommendation for proposing changes, improvements, bug fixes to the JDK is to start small and stay focused. If you see something, and then work up the courage to say something, be prepared to prove something, and if you get past that point get ready to commit yourself to doing something. Once you are successful with a few small wins, you may be able to move on to bigger changes.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Donald Raab

Donald Raab

Java Champion. Creator of the Eclipse Collections OSS Java library ( Inspired by Smalltalk. Opinions are my own.