Bench: edits timed at the drawn tile; per-cycle document counts; posted chords
This commit is contained in:
7 files changed
+93
-30
No files matched your search
@@ -471,15 +471,11 @@ impl LokView {
|
||||
log::warn!("lok: a tile came back the wrong size");
|
||||
return;
|
||||
};
|
||||
let entry = TileEntry {
|
||||
image: Arc::new(RenderImage::new([Frame::new(image)])),
|
||||
stale: false,
|
||||
};
|
||||
log::debug!("lok: tile {key:?} shown");
|
||||
if let Some(old) = self.tiles.insert(key, entry) {
|
||||
let image = Arc::new(RenderImage::new([Frame::new(image)]));
|
||||
self.clock.painted(tile.generation, Arc::as_ptr(&image) as usize);
|
||||
if let Some(old) = self.tiles.insert(key, TileEntry { image, stale: false }) {
|
||||
self.retired.push(old.image);
|
||||
}
|
||||
self.clock.painted(tile.generation);
|
||||
cx.notify();
|
||||
}
|
||||
Ok(_) => cx.notify(),
|
||||
|
||||
@@ -7,6 +7,8 @@ type Edit = (Instant, Option<u64>, Option<u64>);
|
||||
#[derive(Default)]
|
||||
pub(super) struct EditClock {
|
||||
edit: Option<Edit>,
|
||||
/// The tile that shows the edit, until it is drawn.
|
||||
awaited: Option<usize>,
|
||||
/// The last generation bump: its revision and generation.
|
||||
bumped: (u64, u64),
|
||||
}
|
||||
@@ -42,16 +44,30 @@ impl EditClock {
|
||||
}
|
||||
}
|
||||
|
||||
/// A tile of `generation` came; logs the edit it shows.
|
||||
pub(super) fn painted(&mut self, generation: u64) {
|
||||
if let Some((at, _, Some(shown))) = self.edit
|
||||
/// A tile of `generation` came as `tile`; it awaits drawing.
|
||||
pub(super) fn painted(&mut self, generation: u64, tile: usize) {
|
||||
if let Some((_, _, Some(shown))) = self.edit
|
||||
&& generation >= shown
|
||||
{
|
||||
log::debug!("lok: edit to tile {} ms", at.elapsed().as_millis());
|
||||
self.edit = None;
|
||||
self.awaited = Some(tile);
|
||||
}
|
||||
}
|
||||
|
||||
/// `tile` reached the window; the edit it shows is timed.
|
||||
pub(super) fn drawn(&mut self, tile: usize) {
|
||||
if self.awaited == Some(tile)
|
||||
&& let Some((at, ..)) = self.edit.take()
|
||||
{
|
||||
log::debug!("lok: edit to tile {} ms", at.elapsed().as_millis());
|
||||
self.awaited = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a drawn `tile` would end the timing.
|
||||
pub(super) fn awaits(&self, tile: usize) -> bool {
|
||||
self.awaited == Some(tile)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn running(&self) -> bool {
|
||||
self.edit.is_some()
|
||||
@@ -68,9 +84,12 @@ mod tests {
|
||||
clock.sent();
|
||||
clock.bumped(7, 3);
|
||||
clock.landed(Some(7));
|
||||
clock.painted(2);
|
||||
clock.painted(2, 20);
|
||||
clock.drawn(20);
|
||||
assert!(clock.running(), "an older picture leaves it running");
|
||||
clock.painted(3);
|
||||
clock.painted(3, 30);
|
||||
assert!(clock.running(), "arriving is not yet drawn");
|
||||
clock.drawn(30);
|
||||
assert!(!clock.running(), "the edit's own picture ends it");
|
||||
}
|
||||
|
||||
@@ -80,10 +99,12 @@ mod tests {
|
||||
clock.sent();
|
||||
clock.bumped(6, 3);
|
||||
clock.landed(Some(7));
|
||||
clock.painted(3);
|
||||
clock.painted(3, 30);
|
||||
clock.drawn(30);
|
||||
assert!(clock.running(), "a batch before the edit shows the old text");
|
||||
clock.bumped(7, 4);
|
||||
clock.painted(4);
|
||||
clock.painted(4, 40);
|
||||
clock.drawn(40);
|
||||
assert!(!clock.running());
|
||||
}
|
||||
|
||||
@@ -94,4 +115,16 @@ mod tests {
|
||||
clock.landed(None);
|
||||
assert!(!clock.running());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_tile_that_never_draws_keeps_the_edit_open() {
|
||||
let mut clock = EditClock::default();
|
||||
clock.sent();
|
||||
clock.bumped(5, 2);
|
||||
clock.landed(Some(5));
|
||||
clock.painted(2, 50);
|
||||
assert!(clock.awaits(50));
|
||||
clock.drawn(51);
|
||||
assert!(clock.running(), "another tile's drawing does not count");
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,13 @@ impl Render for LokView {
|
||||
)
|
||||
});
|
||||
match painted {
|
||||
Ok(()) => drawn = true,
|
||||
Ok(()) => {
|
||||
drawn = true;
|
||||
let tile = Arc::as_ptr(image) as usize;
|
||||
if this.read(app).clock.awaits(tile) {
|
||||
this.update(app, |view, _| view.clock.drawn(tile));
|
||||
}
|
||||
}
|
||||
Err(error) => log::error!("lok: tile paint failed: {error}"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user