-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Describe the feature
With LazyConstant (formerly StableValue), Java will receive a new default mechanism for lazy initialization which supports constant folding. This issue proposes to change the implementation of the @Getter(lazy = true) to use LazyConstants under the hood:
@Getter(lazy=true) private final double[] cached = expensive();
private double[] expensive() {
double[] result = new double[1000000];
for (int i = 0; i < result.length; i++) {
result[i] = Math.asin(i);
}
return result;
}will become:
@Getter(lazy=true) private final LazyConstant<double[]> cached = LazyConstant.of(() -> {
double[] result = new double[1000000];
for (int i = 0; i < result.length; i++) {
result[i] = Math.asin(i);
}
return result;
});
private double[] expensive() {
return expensive.get();
}Describe the target audience
Everyone could benefit from the performance boost unlocked through constant folding.
Additional context
This would introduce breaking (source) changes, because Lombok would have to change the datatype of the field. As the Lombok documentation already discourages direct field access, I'd argue, that this would be an excusable price to pay.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels