Profiling and Optimizing Java Streams

Eduardo Rosales, Matteo Basso, Andrea Rosà, Walter Binder
{"title":"Profiling and Optimizing Java Streams","authors":"Eduardo Rosales, Matteo Basso, Andrea Rosà, Walter Binder","doi":"10.22152/programming-journal.org/2023/7/10","DOIUrl":null,"url":null,"abstract":"The Stream API was added in Java 8 to allow the declarative expression of data-processing logic, typically map-reduce-like data transformations on collections and datasets. The Stream API introduces two key abstractions. The stream, which is a sequence of elements available in a data source, and the stream pipeline, which contains operations (e.g., map, filter, reduce) that are applied to the elements in the stream upon execution. Streams are getting popular among Java developers as they leverage the conciseness of functional programming and ease the parallelization of data processing. Despite the benefits of streams, in comparison to data processing relying on imperative code, streams can introduce significant overheads which are mainly caused by extra object allocations and reclamations, and the use of virtual method calls. As a result, developers need means to study the runtime behavior of streams in the goal of both mitigating such abstraction overheads and optimizing stream processing. Unfortunately, there is a lack of dedicated tools able to dynamically analyze streams to help developers specifically locate issues degrading application performance. In this paper, we address the profiling and optimization of streams. We present a novel profiling technique for measuring the computations performed by a stream in terms of elapsed reference cycles, which we use to locate problematic streams with a major impact on application performance. While accuracy is crucial to this end, the inserted instrumentation code causes the execution of extra cycles, which are partially included in the profiles. To mitigate this issue, we estimate and compensate for the extra cycles caused by the inserted instrumentation code. We implement our approach in StreamProf that, to the best of our knowledge, is the first dedicated stream profiler for the Java Virtual Machine (JVM). With StreamProf, we find that cycle profiling is effective to detect problematic streams whose optimization can enable significant performance gains. We also find that the accurate profiling of tasks supporting parallel stream processing allows the diagnosis of load imbalance according to the distribution of stream-related cycles at a thread level. We conduct an evaluation on sequential and parallel stream-based workloads that are publicly available in three different sources. The evaluation shows that our profiling technique is efficient and yields accurate profiles. Moreover, we show the actionability of our profiles by guiding stream-related optimizations on two workloads from Renaissance. Our optimizations require the modification of only a few lines of code while achieving speedups up to a factor of 5x. Java streams have been extensively studied by recent work, focusing on both how developers are using streams and how to optimize them. Current approaches in the optimization of streams mainly rely on static analysis techniques that overlook runtime information, suffer from important limitations to detect all streams executed by a Java application, or are not suitable for the analysis of parallel streams. Understanding the dynamic behavior of both sequential and parallel stream processing and its impact on application performance is crucial to help users make better decisions while using streams.","PeriodicalId":224558,"journal":{"name":"Art Sci. Eng. Program.","volume":"2 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2023-02-15","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"2","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Art Sci. Eng. Program.","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.22152/programming-journal.org/2023/7/10","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 2

Abstract

The Stream API was added in Java 8 to allow the declarative expression of data-processing logic, typically map-reduce-like data transformations on collections and datasets. The Stream API introduces two key abstractions. The stream, which is a sequence of elements available in a data source, and the stream pipeline, which contains operations (e.g., map, filter, reduce) that are applied to the elements in the stream upon execution. Streams are getting popular among Java developers as they leverage the conciseness of functional programming and ease the parallelization of data processing. Despite the benefits of streams, in comparison to data processing relying on imperative code, streams can introduce significant overheads which are mainly caused by extra object allocations and reclamations, and the use of virtual method calls. As a result, developers need means to study the runtime behavior of streams in the goal of both mitigating such abstraction overheads and optimizing stream processing. Unfortunately, there is a lack of dedicated tools able to dynamically analyze streams to help developers specifically locate issues degrading application performance. In this paper, we address the profiling and optimization of streams. We present a novel profiling technique for measuring the computations performed by a stream in terms of elapsed reference cycles, which we use to locate problematic streams with a major impact on application performance. While accuracy is crucial to this end, the inserted instrumentation code causes the execution of extra cycles, which are partially included in the profiles. To mitigate this issue, we estimate and compensate for the extra cycles caused by the inserted instrumentation code. We implement our approach in StreamProf that, to the best of our knowledge, is the first dedicated stream profiler for the Java Virtual Machine (JVM). With StreamProf, we find that cycle profiling is effective to detect problematic streams whose optimization can enable significant performance gains. We also find that the accurate profiling of tasks supporting parallel stream processing allows the diagnosis of load imbalance according to the distribution of stream-related cycles at a thread level. We conduct an evaluation on sequential and parallel stream-based workloads that are publicly available in three different sources. The evaluation shows that our profiling technique is efficient and yields accurate profiles. Moreover, we show the actionability of our profiles by guiding stream-related optimizations on two workloads from Renaissance. Our optimizations require the modification of only a few lines of code while achieving speedups up to a factor of 5x. Java streams have been extensively studied by recent work, focusing on both how developers are using streams and how to optimize them. Current approaches in the optimization of streams mainly rely on static analysis techniques that overlook runtime information, suffer from important limitations to detect all streams executed by a Java application, or are not suitable for the analysis of parallel streams. Understanding the dynamic behavior of both sequential and parallel stream processing and its impact on application performance is crucial to help users make better decisions while using streams.
分析和优化Java流
Java 8中添加了Stream API,以允许数据处理逻辑的声明式表达式,通常是在集合和数据集上进行类似map-reduce的数据转换。Stream API引入了两个关键的抽象。流,它是数据源中可用元素的序列,流管道,它包含在执行时应用于流中的元素的操作(例如map, filter, reduce)。流在Java开发人员中越来越受欢迎,因为它们利用了函数式编程的简洁性并简化了数据处理的并行化。尽管有流的好处,但与依赖于命令式代码的数据处理相比,流可能会带来显著的开销,这主要是由额外的对象分配和回收以及使用虚拟方法调用引起的。因此,开发人员需要研究流的运行时行为,以减轻这种抽象开销并优化流处理。不幸的是,缺乏能够动态分析流的专用工具来帮助开发人员明确地定位降低应用程序性能的问题。在本文中,我们讨论了流的分析和优化。我们提出了一种新的分析技术,用于根据经过的引用周期测量流执行的计算,我们使用它来定位对应用程序性能有重大影响的有问题的流。虽然准确性对于这一点至关重要,但插入的检测代码会导致执行额外的周期,这些周期部分包含在配置文件中。为了缓解这个问题,我们估计并补偿插入的仪表代码造成的额外周期。我们在StreamProf中实现了我们的方法,据我们所知,它是Java虚拟机(JVM)的第一个专用流分析器。使用StreamProf,我们发现循环分析可以有效地检测有问题的流,其优化可以显著提高性能。我们还发现,支持并行流处理的任务的准确分析允许根据线程级别上流相关周期的分布来诊断负载不平衡。我们对顺序和并行的基于流的工作负载进行了评估,这些工作负载在三个不同的来源中公开可用。评价结果表明,我们的轮廓技术是有效的,并得到了准确的轮廓。此外,我们通过在Renaissance的两个工作负载上指导与流相关的优化,展示了我们的配置文件的可操作性。我们的优化只需要修改几行代码,同时实现高达5倍的加速。最近的工作对Java流进行了广泛的研究,重点关注开发人员如何使用流以及如何优化流。当前的流优化方法主要依赖于静态分析技术,这些技术忽略了运行时信息,在检测Java应用程序执行的所有流时受到重要的限制,或者不适合分析并行流。了解顺序和并行流处理的动态行为及其对应用程序性能的影响对于帮助用户在使用流时做出更好的决策至关重要。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:604180095
Book学术官方微信
小红书