Repository navigation
fix(map): the held-places grid is made without a box kept per row (C2f-6) #2906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,16 +41,24 @@ impl Clone for Cache { | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| impl Grid { | ||||||||||||||
| /// The grid of `rows`' boxes: one walk over every row's vertices, with a box a row (32 bytes) | ||||||||||||||
| /// kept only while the grid is made. Capped at 256 by 256 cells, so the cells' own lists stay | ||||||||||||||
| /// small (about 1.5 MB at most) whatever the layer's size; a row's box is listed in at most | ||||||||||||||
| /// [`MAX_CELLS_PER_ROW`] cells. | ||||||||||||||
| /// The grid of `rows`' boxes, made in two walks over every row's vertices: one for the box | ||||||||||||||
| /// they are all in, one to list each row's box, so no box is kept per row (a list of them | ||||||||||||||
| /// would take 32 bytes a row while the grid is made). Capped at 256 by 256 cells, so the | ||||||||||||||
| /// cells' headers (24 bytes each) take about 1.5 MB at most; each row is listed at 4 bytes a | ||||||||||||||
| /// cell it is in, in at most [`MAX_CELLS_PER_ROW`] cells (usually one to four), or once in | ||||||||||||||
| /// the wide list. | ||||||||||||||
| fn new(rows: &Features) -> Grid { | ||||||||||||||
| // A box per row, empty for a row without a shape or a place (`Geometry::extent` leaves | ||||||||||||||
| // out a coordinate that isn't a number, so every other box is finite). | ||||||||||||||
| let boxes: Vec<Extent> = (0..rows.len()).map(|i| rows.geometry(i).map_or(Extent::EMPTY, |g| g.extent())).collect(); | ||||||||||||||
| let total = boxes.iter().fold(Extent::EMPTY, |t, e| if e.is_empty() { t } else { t.union(e) }); | ||||||||||||||
| let shaped = boxes.iter().filter(|e| !e.is_empty()).count(); | ||||||||||||||
| // A row's box, empty for a row without a shape or a place (`Geometry::extent` leaves out a | ||||||||||||||
| // coordinate that isn't a number, so every other box is finite). | ||||||||||||||
| let box_of = |i: usize| rows.geometry(i).map_or(Extent::EMPTY, |g| g.extent()); | ||||||||||||||
| let (mut total, mut shaped) = (Extent::EMPTY, 0usize); | ||||||||||||||
| for i in 0..rows.len() { | ||||||||||||||
| let e = box_of(i); | ||||||||||||||
| if !e.is_empty() { | ||||||||||||||
| total = total.union(&e); | ||||||||||||||
| shaped += 1; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+54
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This removes the 32-byte-per-row box list, but the grid is still built synchronously from Category: performance
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not timed. The second walk does the same work as the first, one |
||||||||||||||
| // About one row a cell. | ||||||||||||||
| let cols = ((shaped as f64).sqrt().ceil() as usize).clamp(1, 256); | ||||||||||||||
| let mut grid = Grid { | ||||||||||||||
|
|
@@ -63,7 +71,8 @@ impl Grid { | |||||||||||||
| wide: Vec::new(), | ||||||||||||||
| beyond: false, | ||||||||||||||
| }; | ||||||||||||||
| for (i, e) in boxes.iter().enumerate() { | ||||||||||||||
| for i in 0..rows.len() { | ||||||||||||||
| let e = &box_of(i); | ||||||||||||||
| let Ok(row) = u32::try_from(i) else { | ||||||||||||||
| // Past 4 billion rows a row can't be listed: every search looks at them all. | ||||||||||||||
| grid.beyond = true; | ||||||||||||||
|
|
@@ -126,8 +135,8 @@ impl Grid { | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| impl Cache { | ||||||||||||||
| /// The rows of `rows` whose shape's box may meet `within` (a superset of those that do; never | ||||||||||||||
| /// one without a shape), each once, in order. The grid is made again only once the rows | ||||||||||||||
| /// The rows of `rows` whose shape's box may meet `within` (a superset of those that do; one | ||||||||||||||
| /// without a shape only past `u32::MAX` rows, when every row is given), each once, in order. The grid is made again only once the rows | ||||||||||||||
| /// change. | ||||||||||||||
|
Comment on lines
+138
to
140
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reflowed doc comment has one line about 140 characters long, and the last line holds only "change.". Rewrapping it keeps the lines under the usual width:
Suggested change
Category: quality
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This merged before the fix was pushed; the rewrap goes into the next C2f PR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Carried into #3018 (C2f-7 part 2) as promised. |
||||||||||||||
| pub(super) fn touching(&self, rows: &Features, within: &Extent) -> Vec<usize> { | ||||||||||||||
| // The grid is disposable; a poisoned lock does not invalidate the features themselves. | ||||||||||||||
|
|
||||||||||||||
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.
The memory comment says each row is listed "at 4 bytes a cell it is in", but the cell lists are
Vec<u32>, and a growingVeckeeps spare capacity, so the real figure can be higher than 4 bytes per listing. "(usually one to four)" is also not measured anywhere in this PR. Either say "at least 4 bytes" or measure withcargo xtask memoryand state the number. This matters because the comment is the place that records the grid's cost against the layer size.Category: quality
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.
This merged before the fix was pushed. The next C2f PR changes the comment to "at least 4 bytes per listing, more where a cell's list keeps spare room" and drops the unmeasured "usually one to four".
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.
Carried into #3018 (C2f-7 part 2) as promised.