cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Swapped out static tag approach with `ClassValue` cache

Open djspiewak opened this issue 9 months ago • 6 comments
trafficstars

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

djspiewak avatar Feb 05 '25 15:02 djspiewak

Ah, unfortunate discovery: ClassValue doesn't exist on Scala Native!

djspiewak avatar Feb 06 '25 23:02 djspiewak

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

armanbilge avatar Feb 07 '25 03:02 armanbilge

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.

djspiewak avatar Feb 07 '25 19:02 djspiewak

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.

armanbilge avatar Feb 10 '25 21:02 armanbilge

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.

djspiewak avatar Feb 12 '25 16:02 djspiewak

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

armanbilge avatar Feb 16 '25 18:02 armanbilge