Skip to content

<functional>: std::function: avoid one indirection for SFO #969

@AlexGuteniev

Description

@AlexGuteniev

@MikeGitb mentioned in #964 (comment)

Note that the self-referencing is inherent to the Small Functor Optimization which is critically important for performance.

Are you sure? I thought Sean Parent had shown in his lightning talk "Polymorphic Task Template in Ten" (Meeting C++ 2017) how this works without the extra pointer: https://www.youtube.com/watch?v=2KGkcGtGVM4. I don't remember if there were any problems with his implementation that would prevent the same implementation strategy in std::function.


Will try to explain very briefly:

Currently std::function uses pointer to small implementation in its buffer and large implementation on heap.

It could instead both place small and large implementation in its buffer. In this case, large implementation data has to be on heap, but vptr of large implementation is still in the buffer. But both implementations are on a known location, so no pointer to it is needed.

This would result in avoiding extra indirection (both pointer size and run-time pointer chasing).

This will also make std::function not self-referencing ( #964 will be presumably fixed by compiler, but it might come handy if uses decides to move std::function objects with memcpy ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceMust go fastervNextBreaks binary compatibility

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions