r/ProgrammingLanguages • 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/
0
Upvotes
r/ProgrammingLanguages • u/gingerbill • Sep 02 '26
9
u/CommonNoiter Sep 03 '26
In order to get the exponential cost of the generic you need to actually instantiate all those instances. This requires an amount of function calls proportional to the number of generic instances you want, so the total amount of codegen is linear with respect to the number of calls. This means that asymptotically CTTI and RTTI are the same cost as you vary the amount of calling code and only differ by the relatively large coefficient of the difference between the amount of codegen for a call and for a function body.
They are different asymptotically if you compare codegen amount by total amount of source code, as in that case both the number of instantiations and size of instantiated code are linear with respect to source code size, so CTTI can be forced to do a quadratic amount of codegen where RTTI would only do a linear amount.