-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
It might be cheaper to initialize large constants more like a lazy static initializer instead of precomputing the value during startup. This would depend on the startup cost of evaluating the expression vs the cost of creating a function that evaluates the expression.
#25230 would be useful in aggregating the non-shared sub-constants of the constant into a larger expression which might be worth deferring even though the non-aggregated parts are not.
Lazy-init constants could reference other lazy-init constants, but eager-initialized constants should not reference lazy-init constants in the same deferred part, since that would force the lazy-init to be executed early.
The lazy initialization mechanics can be much simpler that lazy static initialization since constants can neither fail in the initializer nor be assigned before being initialized.