Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 31-Mar-2022 | - | ||||
src/ | H | 31-Mar-2022 | - | 151 | 108 | |
.cargo-checksum.json | H A D | 03-May-2022 | 89 | 1 | 1 | |
CHANGELOG.md | H A D | 31-Mar-2022 | 342 | 18 | 12 | |
Cargo.toml | H A D | 31-Mar-2022 | 904 | 27 | 23 | |
LICENSE-APACHE | H A D | 31-Mar-2022 | 11.1 KiB | 202 | 169 | |
LICENSE-MIT | H A D | 31-Mar-2022 | 1 KiB | 26 | 22 | |
README.md | H A D | 31-Mar-2022 | 1.5 KiB | 36 | 25 | |
bors.toml | H A D | 31-Mar-2022 | 87 | 6 | 4 | |
rustfmt.toml | H A D | 31-Mar-2022 | 53 | 3 | 2 |
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