Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Avoid more allocations when compiling html5ever #37373
Conversation
| @@ -161,7 +162,7 @@ pub fn count_names(ms: &[TokenTree]) -> usize { | |||
| }) | |||
| } | |||
|
|
|||
| pub fn initial_matcher_pos(ms: Rc<Vec<TokenTree>>, sep: Option<Token>, lo: BytePos) | |||
| pub fn initial_matcher_pos(ms: Vec<TokenTree>, sep: Option<Token>, lo: BytePos) | |||
Mark-Simulacrum
Oct 24, 2016
Member
I believe this means that we are now copying/moving the Vec; perhaps we only need &[TokenTree] here?
I believe this means that we are now copying/moving the Vec; perhaps we only need &[TokenTree] here?
nnethercote
Oct 24, 2016
Author
Contributor
The Vec gets put into the MatcherPos, so if it becomes a reference then MatcherPos will need a lifetime paramter and things get more complicated. Copying a Vec shouldn't be that expensive because only three words get copied, right? I did a Cachegrind run and this commit caused the number of instructions executed to drop.
The Vec gets put into the MatcherPos, so if it becomes a reference then MatcherPos will need a lifetime paramter and things get more complicated. Copying a Vec shouldn't be that expensive because only three words get copied, right? I did a Cachegrind run and this commit caused the number of instructions executed to drop.
oli-obk
Oct 24, 2016
Contributor
Cloning a Vec copies all the allocated elements. But it can probably use memcpy, so that should be fast.
Cloning a Vec copies all the allocated elements. But it can probably use memcpy, so that should be fast.
nnethercote
Oct 24, 2016
Author
Contributor
I was under the impression that passing a Vec as an argument to a function doesn't clone it. Have I got that wrong?
I was under the impression that passing a Vec as an argument to a function doesn't clone it. Have I got that wrong?
oli-obk
Oct 24, 2016
Contributor
oh right... forget I said anything, I thought the Rc was there to prevent the cloning.
oh right... forget I said anything, I thought the Rc was there to prevent the cloning.
|
Are those changes speeding up the compilation of other programs too? Optimizations should be added only after there's a more general proof of their quality. |
|
It looks like SmallVec should impl Deref/DerefMut so that the .as_slice()/mut calls become redundant, and it's more of a drop in replacement for Vec. |
| .cloned() | ||
| .collect()), | ||
| let mut cur_eis = SmallVector::zero(); | ||
| cur_eis.push(initial_matcher_pos(ms.iter().cloned().collect(), |
oli-obk
Oct 24, 2016
Contributor
this should be a simple ms.to_owned()
this should be a simple ms.to_owned()
nrc
Oct 25, 2016
Member
And could this use SmallVector::one instead of zero and push?
And could this use SmallVector::one instead of zero and push?
|
r=me with the nits in macro_parser.rs addressed |
74ecc3f
to
d37650a
This avoids 800,000 heap allocations when compiling html5ever.
This avoids 800,000 heap allocations when compiling html5ever. It requires tweaking `SmallVector` a little.
This avoids 800,000 allocations when compiling html5ever.
d37650a
to
c440a7a
|
Updated to address comments, including adding |
|
@bors: r+ |
|
|
Avoid more allocations when compiling html5ever These three commits reduce the number of allocations performed when compiling html5ever from 13.2M to 10.8M, which speeds up compilation by about 2%. r? @nrc
Avoid more allocations when compiling html5ever These three commits reduce the number of allocations performed when compiling html5ever from 13.2M to 10.8M, which speeds up compilation by about 2%. r? @nrc
These three commits reduce the number of allocations performed when compiling html5ever from 13.2M to 10.8M, which speeds up compilation by about 2%.
r? @nrc