Skip to content
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

use java.lang.ClassValue instead of IO.tag #4260

Open
xuwei-k opened this issue Jan 29, 2025 · 2 comments · May be fixed by #4266
Open

use java.lang.ClassValue instead of IO.tag #4260

xuwei-k opened this issue Jan 29, 2025 · 2 comments · May be fixed by #4266

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented Jan 29, 2025

I think java.lang.ClassValue is faster than current implementation.

Jmh / run -i 10 -wi 10 -f 1 -t 1 cats.effect.benchmarks.TagBenchmark
[info] Benchmark                 Mode  Cnt         Score        Error  Units
[info] TagBenchmark.classValue  thrpt   10  10348652.195 ± 116363.873  ops/s
[info] TagBenchmark.tag         thrpt   10   7336411.108 ±  91988.686  ops/s
@djspiewak
Copy link
Member

djspiewak commented Feb 5, 2025

Oh this is incredible and I didn't know about it. What this allows us to do is eliminate a megamorphic virtual dispatch. The replacement looks to be a tableswitch. Without digging into the JIT output, I can only guess about how it gets inlined, but clearly this gives the runtime a lot more information to work with. Very nice.

@djspiewak
Copy link
Member

The linked scala/scala PR is really interesting. I did a similar set of benchmarking (though more specialized to IOFiber and obviously not including ClassValue) and found that virtual dispatch fell behind tableswitch more or less across the board. I suspect there's a subtle interaction with the inliner here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants