cats-effect
cats-effect copied to clipboard
Swapped out static tag approach with `ClassValue` cache
All credit goes to @xuwei-k here. I even cribbed his code more or less directly. I haven't yet run the full set of benchmarks so hold off on merging.
Fixes #4260
Ah, unfortunate discovery: ClassValue doesn't exist on Scala Native!
Darn, unless we do some messy source-splitting, that means we won't get this in until we complete the 0.5 upgrade ... anyway I opened an issue.
- https://github.com/scala-native/scala-native/issues/4209
Yeah I briefly thought about doing some sort of weird split thing but it would be bonkers. So I'll probably just push this far enough to get a full set of benchmark results so we can prioritize down the road, then leave it on ice until SN catches up.
Studied the implementation of ClassValue a bit, it still has some fairly complicated machinery. I wonder if we can beat it by doing something similar and simpler (I will prototype this later when I have time). The one definitive advantage that ClassValue has is that it's implemented by a field on Class.
The one definitive advantage that ClassValue has is that it's implemented by a field on Class.
Ostensibly it's also something the JIT understands. I think that's the real advantage, but we would need to actually examine the hotspot outputs to be sure.
I wonder if we can beat it by doing something similar and simpler (I will prototype this later when I have time).
I made an experimental "ClassByteMap" in 1472f3d252eb0d79c161c9f5d01dec249ce7252b, seems to be faster than ClassValue:
Benchmark Mode Cnt Score Error Units
TagBenchmark.classByteMap thrpt 20 10417078.521 ± 466789.955 ops/s
TagBenchmark.classValue thrpt 20 8920919.389 ± 110746.064 ops/s
TagBenchmark.tag thrpt 20 7082499.380 ± 132528.920 ops/s