concept performance in category java

appears as: performce, performce, performces, A performce
Modern Java in Action: Lambdas, streams, reactive and functional programming

This is an excerpt from Manning's book Modern Java in Action: Lambdas, streams, reactive and functional programming.

This is a good solution, but notice how you have to duplicate most of the implementation for traversing the inventory and applying the filtering criteria on each apple. This is somewhat disappointing because it breaks the DRY (don’t repeat yourself) principle of software engineering. What if you want to alter the filter traversing to enhance performance? You now have to modify the implementation of all of your methods instead of only a single one. This is expensive from an engineering-effort perspective.

Listing 7.1. Measuring performance of a function summing the first n numbers
@BenchmarkMode(Mode.AverageTime)                     #1
@OutputTimeUnit(TimeUnit.MILLISECONDS)               #2
@Fork(2, jvmArgs={"-Xms4G", "-Xmx4G"})               #3
public class ParallelStreamBenchmark {
    private static final long N= 10_000_000L;

    @Benchmark                                       #4
    public long sequentialSum() {
        return Stream.iterate(1L, i -> i + 1).limit(N)
                     .reduce( 0L, Long::sum);
    }

    @TearDown(Level.Invocation)                      #5
    public void tearDown() {
        System.gc();
    }
}

This time the performance of your method isn’t important. The only relevant thing is that each execution returns a different result, all distant from the correct value of 50000005000000. This is caused by the fact that multiple threads are concurrently accessing the accumulator and, in particular, executing total += value, which, despite its appearance, isn’t an atomic operation. The origin of the problem is that the method invoked inside the forEach block has the side effect of changing the mutable state of an object shared among multiple threads. It’s mandatory to avoid these kinds of situations if you want to use parallel streams without incurring similar bad surprises.

Now you know that a shared mutable state doesn’t play well with parallel streams and with parallel computations in general. We’ll come back to this idea of avoiding mutation in chapters 18 and 19 when discussing functional programming in more detail. For now, keep in mind that avoiding a shared mutable state ensures that your parallel stream will produce the right result. Next, we’ll look at some practical advice you can use to figure out when it’s appropriate to use parallel streams to gain performance.

The Java Module System

This is an excerpt from Manning's book The Java Module System.

  • The Java Platform Module System exists to make Java understand the JAR graph, which brings artifact-level modularity to the language. The most important goals are reliable configuration and strong encapsulation as well as improved security, maintainability, and performance.
  • And jlink helps here, as well. It doesn’t stop at linking platform modules—it can also create application images, which include app code as well as library and framework modules. This allows your build process to produce an entirely self-contained deployment unit that consists of your entire app with exactly the platform modules it needs, optimized for image size and performance as you see fit, and launchable with a simple call to a native script.

    Java 8 in Action: Lambdas, streams, and functional-style programming

    This is an excerpt from Manning's book Java 8 in Action: Lambdas, streams, and functional-style programming.

    This is a good solution, but notice how you have to duplicate most of the implementation for traversing the inventory and applying the filtering criteria on each apple. This is somewhat disappointing because it breaks the DRY (don’t repeat yourself) principle of software engineering. What if you want to alter the filter traversing to enhance performance? You now have to modify the implementation of all of your methods instead of a single one. This is expensive from an engineering effort perspective.

    Listing 7.1. Measuring performance of a function summing the first n numbers
    public long measureSumPerf(Function<Long, Long> adder, long n) { long fastest = Long.MAX_VALUE; for (int i = 0; i < 10; i++) { long start = System.nanoTime(); long sum = adder.apply(n); long duration = (System.nanoTime() - start) / 1_000_000; System.out.println("Result: " + sum); if (duration < fastest) fastest = duration; } return fastest; }

    This time the performance of your method isn’t important: the only relevant thing is that each execution returns a different result, all very distant from the correct value of 50000005000000. This is caused by the fact that multiple threads are concurrently accessing the accumulator and in particular executing total += value, which, despite its appearance, isn’t an atomic operation. The origin of the problem is that the method invoked inside the forEach block has the side effect of changing the mutable state of an object shared among multiple threads. It’s mandatory to avoid these kinds of situations if you want to use parallel Streams without incurring similar bad surprises.

    Now you know that shared mutable state doesn’t play well with parallel streams and with parallel computations in general. We’ll come back to this idea of avoiding mutation in chapters 13 and 14 when discussing functional programming in more detail. For now, keep in mind that avoiding shared mutable state ensures that your parallel Stream will produce the right result. Next, we’ll look at some practical advice you can use to figure out when it’s appropriate to use parallel streams to gain performance.

    Spring Integration in Action

    This is an excerpt from Manning's book Spring Integration in Action.

    The interaction model doesn’t affect the logical design of the system (how many channels, what endpoints, how they’re connected). But to improve the performance, you may want to free the message sending thread (which belongs to the main application) from executing the processing of orders and notifications and do that work asynchronously in the background, as seen in figure 2.8.

    The Well-Grounded Java Developer

    This is an excerpt from Manning's book The Well-Grounded Java Developer.

    One key decision that the well-grounded Java developer always takes into consideration is the scope of the objects that they’re dealing with. Stateless objects that are relatively cheap to create don’t need to worry about having their scope set. The JVM will have no trouble creating and destroying these as needed. (Chapter 6 covers the JVM and performance in more detail.)

    Figure 6.1. A performance elbow

    For a few halcyon years in the middle of last decade, it seemed as though performance was not really a concern. Clock speeds were going up and up, and it seemed that all software engineers had to do was to wait a few months, and the improved CPU speeds would give an uptick to even badly written code.

    How, then, did things go so wrong? Why are clock speeds not improving that much anymore? More worryingly, why does a computer with a 3 GHz chip not seem much faster than one with a 2 GHz chip? Where has this trend for software engineers across the industry to be concerned about performance come from?

    Most of our discussion of performance tuning centers on systems where all the processing takes places on a single host. But you should be aware that there are a number of special problems that arise when doing performance tuning of systems spread over a network. Synchronization and timing over networks is far from easy, and not only over the internet. Even Ethernet networks will show these issues.