Skip to content

Conversation

@khatchad
Copy link

Apply Optimize Java 8 Streams Refactoring

Description

This is a semantics-preserving automated refactoring that attempts to optimize code using Java 8 streams when it is safe and possibly advantageous to do so. It may make certain streams parallel, others sequential, and unorder streams where necessarily. The tool does not add new functionality; it only rearranges existing code in an effort to increase its performance. Your program's results should be the same before and after the refactoring.

Details

  • We are evaluating a research prototype automated refactoring Eclipse plug-in called Optimize Java 8 Streams Refactoring. We have applied the tool to your project in the hopes of receiving feedback.
  • The approach is very conservative. That may mean that not all changes that can be made were made.
  • The source code should be semantically equivalent to the original.
  • The tool does not assess overhead vs. the amount of data processed; it only performs the refactoring when it is safe and possibly advantageous to do so. However, we ran several performance tests on the refactored code (see below).

Performance Evaluation

We did not find dedicated performance tests in your project (please let us know if we missed it). But, we did evaluate our tool on other projects (see iluwatar/java-design-patterns#786 (comment) and numenta/htm.java#539 (comment)). We have found an average speedup of ~3.25 as a result of our refactoring across all of our tests thus far.

Feedback

Thank you for your help in this evaluation! Any feedback you can provide would be very helpful. In particular, we are interested if each of the proposed changes are helpful or not.

@jodastephen
Copy link
Member

In most cases, using parallelStream() is unwise, as it shares a single pool of threads across the whole application. In larger applications, this provides a single point of contention, which can be painful if one of the parallel streams is slow and all the others should be fast.

Applying an automatic tool like this also misses out on the documentation changes that should go with changing the stream to be parallel.

I hope you haven't sent out too many PRs, as your proposed changes make library code worse, not better. Sorry.

@khatchad
Copy link
Author

khatchad commented Aug 21, 2018

Hi @jodastephen. Thank you for the feedback. Indeed, the tool does not currently account for documentation changes. Also, it's focus is on client code, and I did notice that the tool made an explicitly sequential stream (through a boolean argument) parallel.

I should also note that it is also possible for the tool to de-parallelize a stream and unorder it to make parallel processing more efficient. Though, that was not the case in your particular project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants