Switch vs if ?
Laurent Bourgès
bourges.laurent at gmail.com
Thu Jan 18 07:42:38 UTC 2018
Thanks for the concrete code samples.
I will gather my own stats and give you my real benchmark results once I
converted switch(3 cases) to if cascades.
Bye,
Laurent
Le 17 janv. 2018 9:42 PM, "John Rose" <john.r.rose at oracle.com> a écrit :
> On Jan 16, 2018, at 6:59 AM, Roland Westrelin <rwestrel at redhat.com> wrote:
>
>
> I've been working
> on some profiling support for tableswitch/lookupswitch and that should
> make it to a future jdk release.
>
>
> I'm really glad about that! Here's a relevant bug:
> https://bugs.openjdk.java.net/browse/JDK-8143859
>
> Until that stuff is fixed, you might choose to code like this:
>
> if (…is 80% case…)
> …do 80% stuff…
> else if (…is 10% case …)
> …do 10% stuff…
> else switch (…some key…) {
> …many other cases…
> }
>
> But…
>
> What we should be able to write is everything in one
> switch, while the JVM should detect which cases are hot.
> If you think you know what are the hot cases, you could
> emphasize them however you want, e.g., by putting
> them at the top of the switch. So we want to write evenly
> balanced code and get it optimized as if it were written
> as above (unevenly).
>
> — John
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20180118/daf10353/attachment.html>
More information about the hotspot-compiler-dev
mailing list