#containers #memcpy

copyless

Ways to eliminate memcpy calls when using the standard library

5 releases

✓ Uses Rust 2018 edition

0.1.4 Jun 24, 2019
0.1.3 May 31, 2019
0.1.2 Mar 19, 2019
0.1.1 Mar 16, 2019
0.1.0 Mar 16, 2019

#19 in Unix APIs

Download history 14822/week @ 2019-12-17 9582/week @ 2019-12-24 11394/week @ 2019-12-31 18743/week @ 2020-01-07 17872/week @ 2020-01-14 19048/week @ 2020-01-21 19994/week @ 2020-01-28 21150/week @ 2020-02-04 19791/week @ 2020-02-11 21528/week @ 2020-02-18 21019/week @ 2020-02-25 22861/week @ 2020-03-03 21368/week @ 2020-03-10 21535/week @ 2020-03-17 22291/week @ 2020-03-24 21598/week @ 2020-03-31

63,976 downloads per month
Used in 370 crates (14 directly)

MPL-2.0 license

10KB
108 lines

copyless

Build Status Crates.io

Rust abstractions can be zero cost in theory, but often reveal quite a few unnecessary memcpy calls in practice. This library provides a number of trait extensions for standard containers that expose API that is more friendly to LLVM optimization passes and doesn't end up with as many copies.

It aims to accelerate WebRender and gfx-rs.

Background

The memcpy instructions showed in profiles of WebRender running in Gecko. @jrmuizel built a tool called memcpy-find that analyzes LLVM IR and spews out the call stacks that end up producing memcpy instructions. We figured out a way to convince the compiler to eliminate the copies. This library attempts to make these ways available to Rust ecosystem, at least until the compiler gets smart enough ;)

Here is a small example

use copyless::BoxHelper;

enum Foo {
    Small(i8),
    Big([f32; 100]),
}

#[inline(never)]
fn foo() -> Box<Foo> {
    Box::new(Foo::Small(4)) // this has 1 memcopy
    //Box::alloc().init(Foo::Small(4)) // this has 0 memcopies
}

fn main() {
    let z = foo();
    println!("{:?}", &*z as *const _);
}

Playground permalink.

No runtime deps