Skip to content

Conversation

@nical
Copy link
Contributor

@nical nical commented Sep 5, 2018

This allows gecko to attach a callback to the transaction and run it after the scene is built to notify the tab switcher that the work is done.

The first commit adds a drain_filter utility modeled after currently unstable Vec::drain_filter. The idea is to be able to get a vector of operations, and each stage of the pipeline can decide to move operations out of the the array and handle them or let them for the next stages to consume.
Hopefully we can use this to merge back the frame_ops, scene_ops and the other vectors in the Transaction struct.
This was previously inconvenient because of how some operations need to move elements out of the vector but while we need to keep the array alive at the same time, and drain_filter makes that less painful.

This PR is based on top of #2989


This change is Reviewable

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #2989) made this pull request unmergeable. Please resolve the merge conflicts.

match update {
drain_filter(
updates,
|update: &mut ResourceUpdate| match *update {
Copy link
Member

Choose a reason for hiding this comment

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

isn't the update type inferred from the closure argument type? we shouldn't need to specify : &mut ResourceUpdate, unless you want it explicitly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought so too, then I was battling some build errors and ended up putting that and thought it was what helped. Turns out this wasn't what fixed my trouble since it indeed compiles when I remove the argument type now.

device_rect.round_out()
}

/// Run a first callback over all elements in the array. If the callback returns true,
Copy link
Member

Choose a reason for hiding this comment

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

nit: "the first callback"

}

/// Run a first callback over all elements in the array. If the callback returns true,
/// The element is removed from the array and moved to a second callback.
Copy link
Member

Choose a reason for hiding this comment

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

nit: "the element"

/// When that happens, code like:
///
/// ```
/// let filter = |&mut op| {
Copy link
Member

Choose a reason for hiding this comment

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

can we have that in unit tests instead of (or in addition to) the documentation?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think you can even write |&mut op| so checking these by the compiler would help ;)

/// ```
///
/// See https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain_filter
pub fn drain_filter<T, F1, F2>(
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we rename F1 -> Filter and F2 -> Action?

let mut i = 0;
while i != vec.len() {
if filter(&mut vec[i]) {
action(vec.remove(i));
Copy link
Member

Choose a reason for hiding this comment

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

This is quadratic asymptotic complexity, or rather O(N*M) where M is the number of filter matches. Can we do better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can but should we? We'll get the the optimized version for free when the std implementation stabilizes and I am certain this will not show up in profiles.
To be honest it also rubs me the wrong way and I'd probably have made more of an effort if we weren't getting the better implementation through std eventually.

Copy link
Member

Choose a reason for hiding this comment

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

ok, that's fine by me, assuming there is a limited array size on the input

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now the size of resource updates vector is 0 the vast majority of times, 3 while playing a video. occasionally 1 when loading an image, etc.

self.merge(resources);
}

pub fn notify(&mut self, event: ExternalEvent) {
Copy link
Member

Choose a reason for hiding this comment

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

can we have some documentation here on what does this mean? When will the notification be fired, and why we need it.

@nical nical force-pushed the txn-notif branch 3 times, most recently from e626c5f to 11db1a8 Compare September 5, 2018 21:50
// potentially long blob rasterization or scene build is ready to be rendered.
// sp that the tab-switching integration can react adequately when tab
// switching takes too long. For this use case what matters is that the
// notification doesn't fire before scene building.
Copy link
Member

Choose a reason for hiding this comment

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

it's not clear from the description if it fires after blob rasterization or after the scene building


// Note: Gecko uses this to get notified when a transaction that contains
// potentially long blob rasterization or scene build is ready to be rendered.
// sp that the tab-switching integration can react adequately when tab
Copy link
Member

Choose a reason for hiding this comment

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

"sp"

@nical nical force-pushed the txn-notif branch 2 times, most recently from 2034b12 to 2fa053c Compare September 6, 2018 15:42
}
drain_filter(
&mut notifications,
|n| { n.when() == CheckPoint::AfterFrameBuilding },
Copy link
Member

Choose a reason for hiding this comment

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

nit: CheckPoint should be a single word


#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum CheckPoint {
AfterSceneBuilding,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe SceneBuilt and FrameBuilt?

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #3036) made this pull request unmergeable. Please resolve the merge conflicts.

@nical
Copy link
Contributor Author

nical commented Sep 12, 2018

@kvark are we good to go?

@kvark
Copy link
Member

kvark commented Sep 12, 2018

@nical yes, if you are confident that a try push isn't needed here :)

@nical
Copy link
Contributor Author

nical commented Sep 12, 2018

@bors-servo r=kvark

@bors-servo
Copy link
Contributor

📌 Commit 503be4a has been approved by kvark

@bors-servo
Copy link
Contributor

⌛ Testing commit 503be4a with merge fb61f1b...

bors-servo pushed a commit that referenced this pull request Sep 12, 2018
Add external event notifications in transactions.

This allows gecko to attach a callback to the transaction and run it after the scene is built to notify the tab switcher that the work is done.

The first commit adds a drain_filter utility modeled after currently unstable Vec::drain_filter. The idea is to be able to get a vector of operations, and each stage of the pipeline can decide to move operations out of the the array and handle them or let them for the next stages to consume.
Hopefully we can use this to merge back the frame_ops, scene_ops and the other vectors in the `Transaction` struct.
This was previously inconvenient because of how some operations need to move elements out of the vector but while we need to keep the array alive at the same time, and drain_filter makes that less painful.

This PR is based on top of #2989

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/3020)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - status-appveyor, status-taskcluster
Approved by: kvark
Pushing fb61f1b to master...

@bors-servo bors-servo merged commit 503be4a into servo:master Sep 12, 2018
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.

3 participants