Replace all lambdas with method references, when possible
Every time a lambda taking an argument is created, an object is created. This object is unique and makes it harder for the JIT compilation to optimize the code. By replacing lambdas with method references, we help the JIT better understand our code, and reduce object creations* and garbage collection. Using method references also helps humans better understand the code, and might even make compilation faster: the method, and where it lives, is explicitely written: no need to guess it. repoUpgraded.stream().map(n -> n.get()).collect(...); Where does the get method come from? Hard to tell. repoUpgraded.stream().map(NameKey::get).collect() Same line of code, using a method reference. It is clear that the input objects are NameKey-s, and we call the get method on them. * This is technically wrong, as a pointer is created even when we use a method reference, but it is at least smaller than the lambda counterpart. Change-Id: Ic85b1b593d42968f262d3afe49a2ad87a4b766b9
This commit is contained in:
@@ -194,6 +194,6 @@ public class ProcMetricModule extends MetricModule {
|
||||
"proc/jvm/thread/num_live",
|
||||
Integer.class,
|
||||
new Description("Current live thread count").setGauge().setUnit("threads"),
|
||||
() -> thread.getThreadCount());
|
||||
thread::getThreadCount);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user