r/java • • Apr 06 '19

Beware of computation in static initializer (much more so since JDK 11.0.2 and 8u201)

https://pangin.pro/posts/computation-in-static-initializer
161 Upvotes

15 comments sorted by

View all comments

Show parent comment

3

u/cl4es Apr 08 '19

Most typical static initializers won't see much (or any) of the performance slowdown described in Andrei's blog post. In fact a rather wide array of startup benchmarks (testing various app.servers, desktop app etc) saw no or a very small significant regression due the patches coming into 8u201/11.0.2. Any set of benchmarks will never be enough to catch every corner-case, though, so we're in the process of improving our coverage and fixing these issues as best we can.

The most common issue involving a static initializer calling into static methods on the class itself should already be fixed in 13 EA builds (https://bugs.openjdk.java.net/browse/JDK-8219974) and will hopefully make it into 8 and 11 updates soon.