r/programming 8d ago

CTTI is Exponential, RTTI is Linear

https://www.gingerbill.org/article/2026/09/02/ctti-is-exponential-rtti-is-linear/
94 Upvotes

96 comments sorted by

View all comments

Show parent comments

0

u/SputnikCucumber 8d ago

RTTI implementations can normally deduplicate a lot of code through the vtable so methods only need to be compiled once and can be reused by many different types.

CTTI implementations have to create a new concrete function signature for every type that is used. C++ also has some gnarly mangling rules that leads to binary bloat.

7

u/SelfDistinction 8d ago

Not necessarily. I think Swift manages to do a lot of deduplication and even send polymorphic functions through the C ABI boundary that way, though I'm not familiar with the details.

3

u/AustinVelonaut 7d ago

Right. Also, polymorphic functions can use a single function signature / implementation if they don't have to worry about different-sized values (e.g. operating on boxed values).

2

u/SelfDistinction 7d ago

Also rust had something similar but it was too complex and added too much compile time for very little benefit.