-
Type: Sub-task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
Fully Compatible
-
QE 2024-03-04, QE 2024-03-18
Deferred is useful for "at-most-once" computation of expensive values.
Currently, it wraps an std::function. Previously, the overhead of std::function in hot paths has been found to be significant.
Deferred does not always require the type erasure of std::function.
Therefore, refactor Deferred to allow storing arbitrary callables. This makes Deferred more flexible, while existing uses which do require type erasure can explicitly use Deferred<std::function<...>>.
With this change, the following does not require an std::function
auto deferredValue = Deferred([&](){ // Do something expensive return thing; }); ... void maybeUseExpensiveValue(auto func) {...} maybeUseExpensiveValue(deferredValue); maybeUseExpensiveValueSomewhereElse(deferredValue);