Use Scala 3 threadUnsafe lazy vals #1818
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
Scala 3 introduced faster mechanism of initialization for
lazy val
s: link to docs.I want to propose adding it to some of the lazy val's in the generated outputs.
The reasoning is that there would be no harm if in the worst case scenario default values are initialized more than once and then GCed, but instead there will be a) no thread-locks during the initialization b) much less byte-code and faster compilation, since they are used a lot. Lazy vals for variables inside of the
*Proto
classes (decoding of the protobufs) left as is (no @threadUnsafe annotation added), since it may be more costly to initialize those values more than once.Here is the example of 2 classes, with annotation and without:
And here is the bytecode that is produced (decompiled to Java code):
What do you think about this change?