-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Migrate rlp from ElasticArray to SmallVec #1957
Conversation
out.append_slice(slice); | ||
fn to_small_vec(slice: &[u8]) -> SmallVec<[u8; 1024]> { | ||
let mut out = SmallVec::new(); | ||
out.extend(slice.to_vec()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
favor slice.iter().cloned()
here, it'll save a heap allocation in a relatively hot function.
Thanks for doing this, @nipunn1313. Got a couple minor grumbles but mostly LGTM. |
Coolio. I fixed up some to_vec() and to to_owned() calls to be efficient/cleaner |
Trying to get smallvec to support Extend here. Looks like the extend inside smallvec is currently implemented as a push loop, but I'm sure that could also be optimized in the future. |
introducing this kind of complexity in our codebase is a retrograde.
if we are to go with |
Hey @gavofyork. I'm working on getting extend() added to the VecLike trait, but insert_slice may be a bit trickier. Let me see what I can do. |
servo/rust-smallvec#28 and servo/rust-smallvec#27 together should upgrade SmallVec to include the mechanisms we need (extend and insert_slice) SmallVec just landed a change to implement Hash, so that handles the issue in kvdb, so this task seems quite tractable now. |
code looks good, but fails tests. |
I do have a couple gripes that concern me before landing
I could probably get SmallVec to support InsertMany, but I think it'll be a little tougher to get support for the fast version. That being said, I don't suspect that these code paths will get ruined by using the iterable implementation since it's typically copying <= 128 bytes at a time. Want to point out these disadvantqges so we are aware of them. |
Helps with 1822
Only one spot left where we're having a code complexity regression (insert_slice).
Changes Unknown when pulling 4a03f6e on nipunn1313:rlp into * on ethcore:master*. |
Master:
This PR:
The empty lists case got a lot faster, but everything else got a bit slower. I think the |
Made an |
@arkpar what do you think? |
@rphmeier. I believe that elastic array uses a memcpy for extend, but currently SmallVec uses a (somewhat inefficient) series of ptr::write in a loop. I don't think your insert_many crate is using that optimization and it definitely doesn't address all the calls to Extend. I set up a PR to use memcpy for extend and insert_many in SmallVec. |
The master
this pr:
this pr with
|
I've done a little more testing and I think what gives |
@rphmeier Is that for extend or for insert_many operation? Can you elaborate a little on which optimization you're referring to? Seems like I should add some benchmarks to my PR. |
@nipunn No, the optimization I'm speaking of can be seen in
|
closing due to inactivity - please reopen on further activity. |
i've checked up on this every once in a while -- seems that we're waiting on the smallvec PRs before this can move forward. See servo/rust-smallvec#28 and servo/rust-smallvec#29 Note to @nipunn1313: in the meantime, RLP has moved to its own crate and your changes will need to be rebased against that. Thanks for undertaking this change, it seems to be a lot more work than initially expected :) |
Yep sounds good. Will reopen when I make progress upstream! --Nipunn On Tue, Sep 27, 2016 at 3:20 AM Robert Habermeier notifications@github.com
|
@nipunn1313 Thanks for the herculean effort on getting servo/rust-smallvec#29 in. It should be possible to revive this effort again, if you're still interested. |
Ah yeah. Perhaps I'll take a look at some point this week. Glad you were still following along! |
This helps out with #1822.
Unfortunately, the smallvec::VecLike trait does not support a firsthand extend operation, so I had to replace those with push loops. It is slightly less ergonomic, but should hopefully compile away into the same code. We can likely upstream this improvement to smallvec's VecLike trait.