[External] : pattern matching performance issue

Chen Liang chen.l.liang at oracle.com
Wed Feb 25 22:53:54 UTC 2026


Confidential - Oracle Restricted \Including External Recipients

Hi Mosin, thanks for the report!
I have created https://bugs.openjdk.org/browse/JDK-8378724 for further investigation for now.

Regards, Chen


________________________________
From: amber-dev <amber-dev-retn at openjdk.org> on behalf of Мосин Николай <mosinnik at yandex.ru>
Sent: Tuesday, February 24, 2026 10:59 AM
To: amber-dev at openjdk.org <amber-dev at openjdk.org>
Subject: [External] : pattern matching performance issue

I faced with degradation of pattern matching switch to analogue if-else with instance of and even on if-else with equals() on classes, 7% degradation to both.   First getType: ```     public static byte getType(IBlock block) {         Class<?
ZjQcmQRYFpfptBannerStart
This Message Is From an Untrusted Sender
You have not previously corresponded with this sender.
Report Suspicious<https://us-phishalarm-ewt.proofpoint.com/EWT/v1/ACWV5N9M2RV99hQ!Nh27domO-0hu9XBh93OV-0_YZO1SZXkSSsbA5RZFwXJx5EWjx3t8aGxGpWxh-HiBGqiWNnqMbGpU-d0$>

ZjQcmQRYFpfptBannerEnd
I faced with degradation of pattern matching switch to analogue if-else with instance of and even on if-else with equals() on classes, 7% degradation to both.

First getType:
```
    public static byte getType(IBlock block) {
        Class<? extends IBlock> blockClass = block.getClass();
        if (blockClass.equals(FlatBlock.class)) {
            return FLAT_BLOCK;
// and so on
```

Second getType2:
```
    public static byte getType2(IBlock block) {
        return switch (block) {
            case FlatBlock _ -> FLAT_BLOCK;
// and so on
```

Third getType3 - got from IDEA auto replacing on getType2 switch:
```
    public static byte getType3(IBlock block) {
        if (Objects.requireNonNull(block) instanceof FlatBlock) {
            return FLAT_BLOCK;
// and so on
```

JMH results:
```
Benchmark                       Mode  Cnt     Score     Error  Units
GeoDriverBenchParams.getType   thrpt    5  7396,383 ± 124,904  ops/s
GeoDriverBenchParams.getType2  thrpt    5  6903,404 ± 119,514  ops/s
GeoDriverBenchParams.getType3  thrpt    5  7455,847 ± 108,161  ops/s
```

Tested on openjdk and temurin both 25.0.2, both have almost the same values

What problem could be?

Repo and jmh to reproduce: https://github.com/mosinnik/l2-geo/blob/sealed_1/src/test/java/ru/mosinnik/l2eve/geodriver/jmh/GeoDriverBenchParams.java

Confidential - Oracle Restricted \Including External Recipients
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20260225/8d7dc9b4/attachment-0001.htm>


More information about the amber-dev mailing list