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

Eliminate a redundant alloc+copy of each frame #2852

Merged
merged 2 commits into from
Jul 14, 2024

Conversation

cgutman
Copy link
Collaborator

@cgutman cgutman commented Jul 14, 2024

Description

The streaming code is copying the entire frame into a new std::vector (using the slow std::back_inserter() too) just to prepend the frame header, right before it copies it a second time to insert the packet headers. We can easily consolidate these operations into one to prevent a useless allocation and copy of every frame we encode.

This isn't the only redundant copy left (fec::encode() does one), but it's the only one that's easy to get rid of. Removing more copies requires scatter/gather I/O support in platf::send()/platf::send_batch() to allow us to submit separate buffers for the header and payload data of each packet. It's not that hard to support S/G, but it's tricky to actually use due to the myriad frame/packet headers (some of which participate in FEC, while others don't).

I also included another change to optimize the copy in fec::encode(). It turns out GCC was generating horrible assembly that was doing a byte-by-byte copy of each frame rather than using the optimized __builtin_memmove() as was the case for the std::copy() in concat_and_insert().

Screenshot

Issues Fixed or Closed

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

Branch Updates

LizardByte requires that branches be up-to-date before merging. This means that after any PR is merged, this branch
must be updated before it can be merged. You must also
Allow edits from maintainers.

  • I want maintainers to keep my branch updated

@cgutman cgutman changed the title Eliminate a redundant alloc+copy for each frame Eliminate a redundant alloc+copy of each frame Jul 14, 2024
Copy link

codecov bot commented Jul 14, 2024

Codecov Report

Attention: Patch coverage is 76.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 9.24%. Comparing base (18e7dfb) to head (fe75e01).

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #2852      +/-   ##
=========================================
+ Coverage    9.12%   9.24%   +0.12%     
=========================================
  Files          97      97              
  Lines       17433   17433              
  Branches     8314    8314              
=========================================
+ Hits         1590    1611      +21     
+ Misses      13021   12936      -85     
- Partials     2822    2886      +64     
Flag Coverage Δ
Linux 6.99% <60.00%> (+0.15%) ⬆️
Windows 4.53% <76.00%> (+0.18%) ⬆️
macOS-12 10.32% <44.00%> (+0.14%) ⬆️
macOS-13 10.23% <44.00%> (+0.15%) ⬆️
macOS-14 10.55% <44.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/stream.cpp 3.42% <76.00%> (+2.31%) ⬆️

... and 25 files with indirect coverage changes

@cgutman cgutman merged commit d57c66f into LizardByte:master Jul 14, 2024
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants