Developer knowledge network · moderated exchange

UnreliableCode 커뮤니티

개발자 연구, 리버스 엔지니어링 및 코딩 커뮤니티

Knowledge index살다
4Categories
919Threads
2.8K게시물
Guide

Why dynamic_cast has runtime performance overhead and how typeid works internally [StackOverflow Architecture Guide]

modern_cpp_artisan
C++ Template Wizard
MEMBER
대표: 124
가입 날짜: Jun 2019
게시물: 29
감사해요: 72
1개월 전 · Jul 16, 2026 9:41 PM
#1

How dynamic_cast<Target*>(ptr) performs safe downcasting in polymorphic class hierarchies:

Unlike static_cast which is a zero-cost compile-time offset adjustment, dynamic_cast traverses Runtime Type Information (RTTI) metadata tables located above the virtual table pointer to verify inheritance relationships.

In deep class hierarchies with multiple inheritance, dynamic_cast performs multiple string/pointer comparisons across the type descriptor graph. In performance-critical loops, prefer tagged sum types (std::variant) or static polymorphism (CRTP).

vtable_slayer
Senior Reverser
MEMBER
대표: 215
가입 날짜: Mar 2018
게시물: 86
감사해요: 61
1개월 전 · Jul 17, 2026 2:50 AM
#2

Profiling a physics loop once revealed 12% CPU time spent entirely in dynamic_cast type checks. Switching to an enum tag check made it 10x faster.

profiler_pat
Performance Hunter
MEMBER
대표: 146
가입 날짜: Aug 2019
게시물: 33
감사해요: 31
1개월 전 · Jul 17, 2026 2:09 PM
#3

RTTI is also disabled in many game engines and embedded systems with -fno-rtti to reduce binary size and avoid virtual dispatch tables overhead.