Streaming APIs are pervasive in mainstream Object-Oriented languages. For example, the Java 8 Stream API allows for functional-like, MapReduce-style operations in processing both finite and infinite data structures. However, using this API efficiently involves subtle considerations like determining when it is best for stream operations to run in parallel, when running operations in parallel can be less efficient, and when it is safe to run in parallel due to possible lambda expression side-effects. In this paper, we describe the engineering aspects of an open source automated refactoring tool called Optimize Streams that assists developers in writing optimal stream software in an (observable) semantics-preserving fashion. Based on a novel ordering and typestate analysis, the tool is implemented as a plug-in to the Eclipse IDE, using both the WALA and SAFE frameworks. It was evaluated on 11 Java projects consisting of ~642 thousand lines of code, where we found that of candidate streams were refactorable, and an average speedup of on a performance suite was observed. We also describe experiences gained from integrating three very different static analysis frameworks to provide developers with an easy-to-use interface for optimizing their stream code to its full potential.
Raffi Khatchadourian, Yiming Tang, Mehdi Bagherzadeh, and Syed Ahmed. A tool for optimizing Java 8 stream software via automated refactoring. In International Working Conference on Source Code Analysis and Manipulation, SCAM ’18. IEEE, September 2018. To appear.