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

Add small-copy optimization for copy_from_slice #37573

Merged
merged 3 commits into from
Dec 1, 2016

Commits on Nov 30, 2016

  1. Add small-copy optimization for io::Cursor

    During benchmarking, I found that one of my programs spent between 5 and
    10 percent of the time doing memmoves. Ultimately I tracked these down
    to single-byte slices being copied with a memcopy in io::Cursor::read().
    Doing a manual copy if only one byte is requested can speed things up
    significantly. For my program, this reduced the running time by 20%.
    
    Why special-case only a single byte, and not a "small" slice in general?
    I tried doing this for slices of at most 64 bytes and of at most 8
    bytes. In both cases my test program was significantly slower.
    ruuda committed Nov 30, 2016
    Configuration menu
    Copy the full SHA
    cd7fade View commit details
    Browse the repository at this point in the history
  2. Move small-copy optimization into copy_from_slice

    Ultimately copy_from_slice is being a bottleneck, not io::Cursor::read.
    It might be worthwhile to move the check here, so more places can
    benefit from it.
    ruuda committed Nov 30, 2016
    Configuration menu
    Copy the full SHA
    3418052 View commit details
    Browse the repository at this point in the history
  3. Move small-copy optimization into <&[u8] as Read>

    Based on the discussion in rust-lang#37573,
    it is likely better to keep this limited to std::io, instead of
    modifying a function which users expect to be a memcpy.
    ruuda committed Nov 30, 2016
    Configuration menu
    Copy the full SHA
    3be2c3b View commit details
    Browse the repository at this point in the history