#container #memcpy

copyless

Ways to eliminate memcpy calls when using the standard library

6 releases

0.1.5 Jun 1, 2020
0.1.4 Jun 24, 2019
0.1.3 May 31, 2019
0.1.2 Mar 19, 2019

#219 in Rust patterns

Download history 10466/week @ 2024-01-05 15270/week @ 2024-01-12 20769/week @ 2024-01-19 12316/week @ 2024-01-26 19122/week @ 2024-02-02 12622/week @ 2024-02-09 11961/week @ 2024-02-16 11744/week @ 2024-02-23 14302/week @ 2024-03-01 14135/week @ 2024-03-08 11968/week @ 2024-03-15 12592/week @ 2024-03-22 16550/week @ 2024-03-29 14603/week @ 2024-04-05 16451/week @ 2024-04-12 9082/week @ 2024-04-19

59,181 downloads per month
Used in 857 crates (24 directly)

MIT/Apache

9KB
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