Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pavel-kirienko opened this issue Mar 26, 2025 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@pavel-kirienko
Copy link
Member

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.

@pavel-kirienko pavel-kirienko added the help wanted Extra attention is needed label Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant