Skip to content

Reduce allocations in SelectorMap (Rule Hash) code - #1299

Merged
bors-servo merged 5 commits into
servo:masterfrom
pradeep90:rule-hash-optimize
Nov 22, 2013
Merged

bors-servo merged 5 commits into
servo:masterfrom
pradeep90:rule-hash-optimize

Conversation

@pradeep90

Copy link
Copy Markdown
Contributor

Issue #1274

Also:

  • Reduce number of clones of Rule
  • Make Rule have Arc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I doubt it makes a difference, but this will be slightly faster and clearer (avoids the bounds check) if you just do:

let mut curr_declarations = ~[];
for rule in rules.iter() { ... }
declarations_list.push(curr_declarations);

The push does a move of curr_declarations so it won't copy.

@pcwalton

Copy link
Copy Markdown
Contributor

Looks pretty good, just one small comment and I'll r+

@pradeep90

Copy link
Copy Markdown
Contributor Author

Yeah. Wasn't sure if push would lead to more allocation :)

bors-servo pushed a commit that referenced this pull request Nov 22, 2013
Issue #1274

Also:
+ Reduce number of clones of Rule
+ Make Rule have Arc<Selector>
@bors-servo bors-servo closed this Nov 22, 2013
@bors-servo
bors-servo merged commit ae1f168 into servo:master Nov 22, 2013
@emberian

Copy link
Copy Markdown
Contributor

@pcwalton @pradeep90 92fa43 and ae1f168 are questionable. It doesn't remove any clones, and it is going to reallocate the vector more often. It shouldn't be calling map on the vector, but rather:

let declarations_list = matching_rules_list.iter().map(|rules| rules.iter().map(|r| r.clone()).collect()).collect();

This will use with_capacity.

eefriedman added a commit to eefriedman/servo that referenced this pull request Sep 29, 2015
Making the Stylist usage threadsafe without unsafe code or extra locking
required some changes to WorkQueue; the changes are mostly straightforward.

Some refactoring of LayoutTaskData was also required: this is basically
just splitting the structure in two so the borrow checker can understand
that building a SharedLayoutContext only borrows part of LayoutTaskData.
The "frozen" part is the part that can't be safely modified while a parallel
work-queue is running.

It might be worth considering switching to some sort of threadsafe
channel to avoid the mutexes... see Rust RFC PR servo#1299.

Fixes servo#2604. Pretty sure the issue with the other version mentioned
there was just that it held on to the lock too long.
eefriedman added a commit to eefriedman/servo that referenced this pull request Sep 29, 2015
Making the Stylist usage threadsafe without unsafe code or extra locking
required some changes to WorkQueue; the changes are mostly straightforward.

Some refactoring of LayoutTaskData was also required: this is basically
just splitting the structure in two so the borrow checker can understand
that building a SharedLayoutContext only borrows part of LayoutTaskData.
The "frozen" part is the part that can't be safely modified while a parallel
work-queue is running.

It might be worth considering switching to some sort of threadsafe
channel to avoid the mutexes... see Rust RFC PR servo#1299.

Fixes servo#2604. Pretty sure the issue with the other version mentioned
there was just that it held on to the lock too long.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants