r/programming • u/gingerbill • Sep 02 '26
CTTI is Exponential, RTTI is Linear
https://www.gingerbill.org/article/2026/09/02/ctti-is-exponential-rtti-is-linear/
97
Upvotes
r/programming • u/gingerbill • Sep 02 '26
View all comments
Show parent comment
1
u/gingerbill Sep 03 '26 edited Sep 03 '26
So parametric polymorphism which creates MORE code than just the call sites, isn't a thing?
By definition it is not linear with the code size.
Even using my basic example there of
N=4andK=5, means a maximum possible of 1365 instantiations of the monomorphized code. So even if there are a million calls that cover all of those permutations, there will only be 1365 instantiations of the parametric polymorphic ("parapoly") procedure.So for each unique permutation, you do get a unique monomorphization. That's not "linear" necessarily, especially if those are determined at compile time through parapoly. You do get more code being generated.
I am not sure why so many people are not understanding this, because this literally happens in many C++ codebases, and it is not hypothetical.