Apparently TLABs are awesome, I guess?
Here's what I get on a 2021 MBP M1 Pro running with OpenJDK 19:
Benchmark Mode Cnt Score Error Units
Benchmarks.immutable ss 15 1.367 ± 0.030 s/op
Benchmarks.immutable:gc.alloc.rate ss 15 463.129 ± 10.164 MB/sec
Benchmarks.immutable:gc.alloc.rate.norm ss 15 664039387.200 ± 461244.704 B/op
Benchmarks.immutable:gc.count ss 15 11.000 counts
Benchmarks.immutable:gc.time ss 15 79.000 ms
Benchmarks.mutableChimney ss 15 1.638 ± 0.057 s/op
Benchmarks.mutableChimney:gc.alloc.rate ss 15 119.821 ± 4.075 MB/sec
Benchmarks.mutableChimney:gc.alloc.rate.norm ss 15 205715684.800 ± 113812.564 B/op
Benchmarks.mutableChimney:gc.count ss 15 4.000 counts
Benchmarks.mutableChimney:gc.time ss 15 175.000 ms
Benchmarks.mutableManual ss 15 1.647 ± 0.072 s/op
Benchmarks.mutableManual:gc.alloc.rate ss 15 119.267 ± 4.969 MB/sec
Benchmarks.mutableManual:gc.alloc.rate.norm ss 15 205688534.400 ± 55861.563 B/op
Benchmarks.mutableManual:gc.count ss 15 2.000 counts
Benchmarks.mutableManual:gc.time ss 15 96.000 ms
I'm not disregarding the idea that memory pressure is a problem but I wonder if it's a problem in tight loops like event folding onto state?
I forgot the command to run this:
scala-cli run --jmh local-mutability-under-spectacle.scala -- -prof gc