Uh oh!
There was an error while loading. Please reload this page.
Specialize Vec::from_elem to use calloc - #40409
Conversation
rust-highfive
commented
Mar 10, 2017
r? @BurntSushi (rust_highfive has picked a reviewer for you, use r? to override) |
leonardo-m
commented
Mar 10, 2017
What's the performance for short (n <= 8)? |
For the following benchmarks, using the default allocator (alloc_jemalloc) on Linux: #[bench]fnbench_big(b:&mutBencher){
b.iter(|| vec![0u8;1024*1024]);}#[bench]fnbench_medium(b:&mutBencher){
b.iter(|| vec![0u8;1024]);}#[bench]fnbench_small(b:&mutBencher){
b.iter(|| vec![0u8;8]);}Before this PR: After this PR: |
Is there a reason why this can't be specialised for all integer types if the value is zero? |
mbrubeck
commented
Mar 10, 2017
It can, and I'm working on a patch to do that. It could also be specialized for floats, and for some less-common types like |
clarfonthey
commented
Mar 10, 2017
I think that specialising for integer zeroes is definitely reasonable (because |
solson
commented
Mar 14, 2017
@whitequark made a good point on IRC: If we had a |
nagisa
left a comment
There was a problem hiding this comment.
(damn github review didn’t get posted)
sfackler
commented
Mar 15, 2017
@solson how would that work here though? This only handles the case of an all-zero initial bit pattern. |
There was a problem hiding this comment.
This fallback seems a bit unfortunate, but I guess there's no other option?
@sfackler My understanding is that for EDIT: See this sentence from this issue description:
|
clarfonthey
commented
Mar 15, 2017
Also one thing to consider is that |
bluss
commented
Mar 15, 2017
@solson the missing part of the explanation is how to identify that |
mbrubeck
commented
Mar 15, 2017
Added a patch to specialize |
solson
commented
Mar 15, 2017
@bluss One basic way would be to iterate over the bytes of |
| } | ||
| #[no_mangle] | ||
| pub extern "C" fn __rust_allocate_zeroed(size: usize, align: usize) -> *mut u8 { |
There was a problem hiding this comment.
I am not super familiar with jemalloc - is calloc faster than unconditionally calling mallocx here?
There was a problem hiding this comment.
Yes, mallocx is parsing the options out from flags’ bitmask, whereas calloc sets them directly. Difference likely negligible though.
There was a problem hiding this comment.
Cool, thanks. Seems fine either way.
sfackler
commented
Mar 15, 2017
r=me other than one dumb question about jemalloc. |
sfackler
commented
Mar 15, 2017
@bors r+ |
bors
commented
Mar 15, 2017
📌 Commit 4961f6c has been approved by |
Specialize Vec::from_elem to use calloc Fixesrust-lang#38723. This specializes the implementation for `u8` only, but it could be extended to other zeroable types if desired. I haven't tested this extensively, but I did verify that it gives the expected performance boost for large `vec![0; n]` allocations with both alloc_system and jemalloc, on Linux. (I have not tested or even built the Windows code.)
Specialize Vec::from_elem to use calloc Fixesrust-lang#38723. This specializes the implementation for `u8` only, but it could be extended to other zeroable types if desired. I haven't tested this extensively, but I did verify that it gives the expected performance boost for large `vec![0; n]` allocations with both alloc_system and jemalloc, on Linux. (I have not tested or even built the Windows code.)
bors
commented
Apr 16, 2017
⌛ Testing commit aad2062 with merge 966a32a... |
bors
commented
Apr 16, 2017
💔 Test failed - status-travis |
Mark-Simulacrum
commented
Apr 16, 2017
Timed out, presumably spurious. Retrying. @bors retry |
Specialize Vec::from_elem to use calloc Fixesrust-lang#38723. This specializes the implementation for `u8` only, but it could be extended to other zeroable types if desired. I haven't tested this extensively, but I did verify that it gives the expected performance boost for large `vec![0; n]` allocations with both alloc_system and jemalloc, on Linux. (I have not tested or even built the Windows code.)
bors
commented
Apr 16, 2017
⌛ Testing commit aad2062 with merge 31bbdc1... |
bors
commented
Apr 16, 2017
💔 Test failed - status-appveyor |
Mark-Simulacrum
commented
Apr 16, 2017
@bors retry
|
bors
commented
Apr 16, 2017
Specialize Vec::from_elem to use calloc Fixes#38723. This specializes the implementation for `u8` only, but it could be extended to other zeroable types if desired. I haven't tested this extensively, but I did verify that it gives the expected performance boost for large `vec![0; n]` allocations with both alloc_system and jemalloc, on Linux. (I have not tested or even built the Windows code.)
bors
commented
Apr 16, 2017
☀️ Test successful - status-appveyor, status-travis |
This is fallout from rust-lang/rust#40409 which requires that all allocators provide a `__rust_alloc_zeroed` function. Fixesjaparic#136.
This is fallout from rust-lang/rust#40409 which requires that all allocators provide a `__rust_alloc_zeroed` function. Fixesjaparic#136.
rust-lang/rust#40409 requires a __rust_alloc_zeroed function.
rust-lang/rust#40409 requires a __rust_alloc_zeroed function.
rust-lang/rust#40409 requires a __rust_alloc_zeroed function.
Fixes#38723.
This specializes the implementation foru8only, but it could be extended to other zeroable types if desired.I haven't tested this extensively, but I did verify that it gives the expected performance boost for large
vec![0; n]allocations with both alloc_system and jemalloc, on Linux. (I have not tested or even built the Windows code.)