Skip to content

Performant, Concurrent, simplified Stream API leveraging Project Loom's virtual threads for efficient concurrent processing. Optimized for multithreaded environments

License

Notifications You must be signed in to change notification settings

YunaBraska/streamline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StreamLine

StreamLine is an enhanced Java Stream API optimized for concurrent processing, leveraging the power of Project Loom's virtual threads. Designed to provide superior performance in multithreaded environments, it simplifies the usage of streams without the common pitfalls of resource management in standard Java streams.

Build Maintainable Coverage Issues Commit Dependencies License Central Tag Javadoc Size Label Label

Motivation

Traditional Java streams are powerful but also come with big limits cause of the shared ForkedJoinPool which is not replaceable and also not programmatically configurable. Java's parallel streams start blocking each other in concurrent environments, leading to performance bottlenecks. Therefore, StreamLine was created to address these shortcomings.

Benefits

  • High-Performance Streaming: Takes full advantage of Project Loom's virtual threads for efficient non-blocking concurrency.
  • Simple API: Offers a straightforward approach to parallel and asynchronous streaming operations.
  • Resource Management: Designed to avoid typical issues related to stream resource management, ensuring cleaner and safer code.
  • Enhanced Scalability: Performs exceptionally well under high-load conditions, scaling effectively across multiple cores.
  • Pure Java: No external dependencies for a lightweight integration.
  • Functional Design: Embraces modern Java functional paradigms.
  • No Reflection: Ensures compatibility with GraalVM native images.

Prerequisites

  • Java 21 or later and for using Project Loom

Usage

import berlin.yuna.streamline.model.StreamLine;

public class Example {
    public static void main(final String[] args) {
        StreamLine.of("one", "two", "three")
            .threads(-1) // Use unlimited threads
            .forEach(System.out::println);
    }
}

With custom thread pool:

import berlin.yuna.streamline.model.StreamLine;

import java.util.concurrent.ForkJoinPool;

public class Example {
    public static void main(final String[] args) {
        final ForkJoinPool executor = new ForkJoinPool();
        
        StreamLine.of(executor, "one", "two", "three")
            .threads(-1) // Use unlimited threads
            .forEach(System.out::println);
    }
}

StreamLine Performance

Each method is tested with 10 concurrent streams including 10 tasks for every stream. CPU cores: 10.

Method Time
Loop [for] 1.86s
Java Stream [Sequential] 1.86s
Java Stream [Parallel] 724ms
StreamLine [Ordered] 118ms
StreamLine [Unordered] 109ms
StreamLine [2 Threads] 512ms

Limitations

  • StreamLine is not compatible with Java 8
  • StreamLine is mainly made for big data processing and not for small data
  • The concurrent processing does not extend to operations returning type-specific streams like IntStream, LongStream, DoubleStream, OptionalInt, OptionalLong, OptionalDouble, etc.
  • StreamLine has more terminal operations than the usual java stream due its simple design - not sure if this is an advantage or disadvantage ^^

About

Performant, Concurrent, simplified Stream API leveraging Project Loom's virtual threads for efficient concurrent processing. Optimized for multithreaded environments

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages