Open Bug 1204160 Opened 4 years ago Updated 4 years ago

Implement a small object optimization for mozilla::Function

Categories

(Core :: MFBT, defect)

defect
Not set

Tracking

()

Tracking Status
firefox43 --- affected

People

(Reporter: botond, Unassigned)

References

Details

Currently, mozilla::Function stores a UniquePtr to the object that stores the wrapped callable. This means every instance of mozilla::Function incurs a dynamic allocation.

We should consider implementing a small-object optimization, where if the size of the callable is smaller than a threshold (say, 16 bytes), the callable is stored in-line. libc++'s implementation of std::function does this. [1]

[1] https://github.com/llvm-mirror/libcxx/blob/6d9da5891f6628ffa9d2f382113a8231121aeee1/include/functional#L1564
You need to log in before you can comment on or make changes to this bug.