Skip to content

Performance improvement: Check if one of the virtual calls can be eliminated #3

@pavel-kirienko

Description

@pavel-kirienko

Currently, triggering a topic requires two virtual calls:

  • First, the triggered Event will invoke trigger on each item on the topic starting from the next one. This works because topics are sorted such that events come first, then behaviors, so we don't have to waste time going through other events (usually there is only one).

  • Then we invoke the Function::operator(), which has to invoke a type-erased function wrapper by pointer.

The second one is theoretically impossible to remove because we need type erasure. The first one, however, could be removed if we used not a single covariant list containing both events and behaviors, but a list of events, where every event may contain its own list of behaviors. In this case, to trigger a topic, one will traverse the list of events, and for each event traverse its own list of behaviors. The number of traversed nodes will remain the same, but there will be only half as many virtual calls. The disadvantage is that event removal will become a rather complicated procedure, because if the removed event has any behaviors on its behavior list, they will have to be moved to another event. Also, the Event memory footprint will be larger because it will have to keep another list.

It is uncertain if this will actually work faster; benchmarking on an actual MCU is needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions