Skip to content

Commit 93c530f

Browse files
author
bors-servo
authored
Auto merge of #94 - arthurprs:union, r=mbrubeck
Use a union to reduce the size of SmallVec [v2] Building on top of #92 by @Amanieu I introduced `triple()` and `triple_mut()` which removed almost all of the runtime overhead. Performance is very comparable. ``` name master:: ns/iter union:: ns/iter diff ns/iter diff % speedup bench_extend 45 47 2 4.44% x 0.96 bench_extend_from_slice 45 43 -2 -4.44% x 1.05 bench_from_slice 45 44 -1 -2.22% x 1.02 bench_insert 615 622 7 1.14% x 0.99 bench_insert_from_slice 101 99 -2 -1.98% x 1.02 bench_insert_many 309 266 -43 -13.92% x 1.16 bench_macro_from_elem 41 37 -4 -9.76% x 1.11 bench_macro_from_list 40 42 2 5.00% x 0.95 bench_push 381 370 -11 -2.89% x 1.03 bench_pushpop 404 420 16 3.96% x 0.96 bench_remove 458 436 -22 -4.80% x 1.05 ``` <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/94) <!-- Reviewable:end -->
2 parents 675221e + cfa1f0c commit 93c530f

File tree

4 files changed

+287
-171
lines changed

4 files changed

+287
-171
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ rust:
55
- stable
66
script: |
77
cargo build --verbose &&
8-
cargo build --all-features --verbose &&
98
cargo test --verbose &&
10-
cargo test --all-features --verbose &&
119
([ $TRAVIS_RUST_VERSION != nightly ] || cargo test --verbose --no-default-features) &&
10+
([ $TRAVIS_RUST_VERSION != nightly ] || cargo test --verbose --features union) &&
1211
([ $TRAVIS_RUST_VERSION != nightly ] || cargo bench --verbose bench)
1312
notifications:
1413
webhooks: http://build.servo.org:54856/travis

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ documentation = "http://doc.servo.org/smallvec/"
1212

1313
[features]
1414
std = []
15+
union = []
1516
default = ["std"]
1617

1718
[lib]
1819
name = "smallvec"
1920
path = "lib.rs"
2021

2122
[dependencies]
23+
unreachable = "1.0.0"
2224
serde = { version = "1", optional = true }
2325

2426
[dev_dependencies]

benches/bench.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ fn gen_insert<V: Vector<u64>>(n: u64, b: &mut Bencher) {
158158

159159
fn gen_remove<V: Vector<u64>>(n: usize, b: &mut Bencher) {
160160
#[inline(never)]
161-
fn remove_noinline<V: Vector<u64>>(vec: &mut V, p: usize) {
162-
vec.remove(p);
161+
fn remove_noinline<V: Vector<u64>>(vec: &mut V, p: usize) -> u64 {
162+
vec.remove(p)
163163
}
164164

165165
b.iter(|| {
166166
let mut vec = V::from_elem(0, n as _);
167167

168168
for x in (0..n - 1).rev() {
169-
remove_noinline(&mut vec, x)
169+
remove_noinline(&mut vec, x);
170170
}
171171
});
172172
}

0 commit comments

Comments
 (0)