Cache stream channel count in hot read/write path#68
Open
gretel wants to merge 1 commit into
Open
Conversation
readStream() and writeStream() are the per-packet hot path. Each call
constructs a uhd::rx_streamer::buffs_type / tx_streamer::buffs_type
which needs the channel count:
uhd::rx_streamer::buffs_type stream_buffs(buffs, stream->get_num_channels());
^^^^^^^^^^^^^^^^^^^^^^^^
uhd::rx_streamer / tx_streamer are abstract base classes; get_num_channels
is a virtual call going through the vtable to the device-specific
streamer implementation. The channel count is established at
get_rx_stream() / get_tx_stream() time and never changes for the
lifetime of the streamer, so making the call once per readStream()
invocation is wasteful.
Cache it in SoapyUHDStream::num_channels at setupStream() time.
struct SoapyUHDStream
{
uhd::rx_streamer::sptr rx;
uhd::tx_streamer::sptr tx;
size_t num_channels = 0; // <-- new
};
Cost: one size_t per stream object. Benefit: one fewer indirect call
per packet on the read/write hot path, where SoapyUHD typically sees
hundreds to thousands of calls per second at high sample rates.
Build verified clean against UHD 4.10.0.0 (uhd-oc 4.10.0.0_1 keg).
No behavior change.
Signed-off-by: Tom Hensel <code@jitter.eu>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cache stream channel count in hot read/write path
Changed
get_num_channels()once atsetupStream()into a_nchanmember; use the cached value inreadStream()/writeStream().Why
get_num_channels()is virtual; called once perrecv/send. Caching skips the per-call dispatch in the hot path.