You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Zhanghao Chen (Jira)" <ji...@apache.org> on 2025/04/27 05:16:00 UTC

[jira] [Created] (FLINK-37735) Replace class.newInstance with constructor.newInstance

Zhanghao Chen created FLINK-37735:
-------------------------------------

             Summary: Replace class.newInstance with constructor.newInstance
                 Key: FLINK-37735
                 URL: https://issues.apache.org/jira/browse/FLINK-37735
             Project: Flink
          Issue Type: Sub-task
          Components: API / Type Serialization System
            Reporter: Zhanghao Chen
         Attachments: image-2025-04-27-13-05-28-554.png, image-2025-04-27-13-14-18-941.png

*Problem*

Flink's PojoSerializer and TupleSerializer uses {{class.newInstance}} to instiantiate a new instance. The {{class.newInstance}} call will get caller class and do access check on each invocation, which consumes much CPU, as depicted in the flame graph below. It is also marked @Deprecated since JDK9, and is subject to removal in later JDK versions.

!image-2025-04-27-13-05-28-554.png|width=730,height=137!

*Proposal*

The suggested alternative is to use {{{}constructor.newInstance{}}}, which allows bypassing the access check completely after setting accessible to true. It also throws more specific exception on invocation error.

The performance gets boosted by ~5% on the Flink POJO benchmark (tested on my laptop with JDK17.0.14):
​ !image-2025-04-27-13-14-18-941.png!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)