Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimization: avoid NotGiven allocations (#17090)
## 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` a `val` instead of `def`. ## Notes - I'm assuming the identity of a `NotGiven` object isn't relevant. - Should I use an internal field and keep `NotGiven.value` as `def` to avoid binary compatibility issues?
- Loading branch information