Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

use streamiterator instead of std iterator #90

Merged
merged 6 commits into from Dec 11, 2021

Conversation

teamplayer3
Copy link
Contributor

The idea behind this is to avoid creating the CanFrame, which is used to transmit the single frames, for every frame. With the StreamIterator the frame can be initialized once per transfer and then be reused.

I did some performance tests on the different implementations for transfers and got these results (cortex-m4 170 MHz, measurements in micros):

frames std iterator streamiterator
1 0 0
2 3 3
3 5 4
4 7 6
5 8 7
6 10 8
7 11 10
8 12 11

This is not that much of a performance improvement. But I think for the future this could be helpful. The now used ArrayVec is very efficient in array initialization and is great for the 8 byte which are used by classic CAN. But if the transmission can send a larger payload, this could give more performance boost. As well, if we have to use a heap allocated payload somehow.

This new implementation will change the usage for transfer messages:

let mut frame_iter = node.transmit(&transfer).unwrap();
while let Some(frame) = frame_iter.next() {
    send...
}

The user gets the frame as a reference. This has no limitations. If the user needs to store the frame to send somehow later, it could be done by cloning the frame. But now the user is responsible for this.

@davidlenfesty davidlenfesty merged commit 5d37215 into master Dec 11, 2021
@davidlenfesty davidlenfesty deleted the alex/stream_iterator branch December 11, 2021 02:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants