• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..31-Mar-2022-

src/H31-Mar-2022-151108

.cargo-checksum.jsonH A D03-May-202289 11

CHANGELOG.mdH A D31-Mar-2022342 1812

Cargo.tomlH A D31-Mar-2022904 2723

LICENSE-APACHEH A D31-Mar-202211.1 KiB202169

LICENSE-MITH A D31-Mar-20221 KiB2622

README.mdH A D31-Mar-20221.5 KiB3625

bors.tomlH A D31-Mar-202287 64

rustfmt.tomlH A D31-Mar-202253 32

README.md

1## copyless
2[![Build Status](https://travis-ci.org/kvark/copyless.svg)](https://travis-ci.org/kvark/copyless)
3[![Crates.io](https://img.shields.io/crates/v/copyless.svg)](https://crates.io/crates/copyless)
4
5Rust 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.
6
7It aims to accelerate [WebRender](https://github.com/servo/webrender) and [gfx-rs](https://github.com/gfx-rs/gfx).
8
9## Background
10
11The `memcpy` instructions showed in profiles of WebRender running in Gecko. @jrmuizel built a tool called [memcpy-find](https://github.com/jrmuizel/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 ;)
12
13## Here is a small example
14
15```rust
16use copyless::BoxHelper;
17
18enum Foo {
19    Small(i8),
20    Big([f32; 100]),
21}
22
23#[inline(never)]
24fn foo() -> Box<Foo> {
25    Box::new(Foo::Small(4)) // this has 1 memcopy
26    //Box::alloc().init(Foo::Small(4)) // this has 0 memcopies
27}
28
29fn main() {
30    let z = foo();
31    println!("{:?}", &*z as *const _);
32}
33```
34
35Playground [permalink](https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=579ab13345b1266752b1fa4400194cc7).
36