-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimization: avoid NotGiven allocations #17090
Conversation
I've just signed the CLA |
Does it actually need a minor release? This seems to be source/tasty/binary-compatible /cc @sjrd. |
We discussed this yesterday. It's not forwards tasty compatible, is the concern. |
Ah, maybe tasty deserialization could be enhanced to make that kind of change actually compatible? |
It's fundamentally incompatible to go from a val to a def, because it makes it unstable. There's no "making it compatible". So going the other direction is not forwards compatible. But you can make it compatible in all directions by storing the instance in a private val, and reading that val in the public def. |
Ah yes, I didn't think of stability, I agree that a def pointing to a private val is the way to go. |
9e77cf6
to
421591f
Compare
Thank you for the feedback! I've just updated the PR to use a private value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
We also discussed going this way on Monday and had decided to just wait for the next minor and make it a val.... |
For these cases (in this instance it's not a big deal) but also personally, I'd love to see you both at the Monday team meetings. |
Yes, I should come more often. |
Problem
I've been working on a library that uses
NotGiven
in the hot path, which ends up producing an extra allocation on every use. I thought JIT compilation would be able to optimize it away but that isn't the case in some benchmarks. For example:Benchmark: https://github.com/fwbrasil/kyo/blob/main/kyo-bench/src/main/scala/kyo/bench/NarrowBindMapBench.scala
Flamegraph: https://getkyo.io/dev/profile/4990c20/kyo.bench.NarrowBindMapBench.forkKyo-Throughput/flame-cpu-forward.html
Solution
Make
NotGiven.value
aval
instead ofdef
.Notes
NotGiven
object isn't relevant.NotGiven.value
asdef
to avoid binary compatibility issues?