Characterizing the Usage and Performance Impact of Java Reflection: An Empirical Study
Reflection enables programs to dynamically inspect and manipulate their own structure, providing flexibility in evolving runtime environments. Java offers this capability through its Reflection API, which supports dynamic object creation, field access, method invocation, and metadata inspection. Despite these advantages, reflection complicates static analysis and may introduce runtime overhead, motivating a comprehensive empirical investigation of its practical use and cost. We analyze reflection usage across 59.4 million Java files from all open-source Java repositories on GitHub, reporting primitive-level statistics. Our results show that reflection is widely adopted but typically confined to specific components, with type retrieval and name inspection dominating usage, while advanced features such as behavioral reflection and generic type inspection also appear in a non-negligible number of repositories. We further measure execution-time and memory overhead across five major JVM implementations on Windows and Linux, considering single-threaded and multithreaded scenarios, and distinguishing startup from steady-state performance under JIT optimization. The results identify clear cost tiers among reflection primitives, substantial steady-state and JVM-dependent overheads, preserved parallel scalability despite high absolute costs, and potentially dramatic slowdowns when reflection is applied pervasively.
Authors
- Francisco Ortín (ORCID: https://orcid.org/0000-0003-1199-8649)
- Miguel García (ORCID: https://orcid.org/0000-0002-3150-2826)
Institutions
- Universidad de Oviedo (ES)
- Munster Technological University (IE)
- Technological University Dublin (IE)
Publication Details
- Journal
- ACM Transactions on Software Engineering and Methodology
- Published
- 2026-05-21
- DOI
- https://doi.org/10.1145/3815583
- Primary Topic
- Software Engineering Research
- Type
- article
- Field-Weighted Citation Impact
- 0.00