Skip to content

fix(map): the held-places grid is made without a box kept per row (C2f-6) - #2906

Merged
pick2510 merged 1 commit into
opengeos:mainfrom
pick2510:crs-held-index-2
Nov 25, 2026
Merged

pick2510 merged 1 commit into
opengeos:mainfrom
pick2510:crs-held-index-2

Conversation

@pick2510

@pick2510 pick2510 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Refs #2032 (C2f-6)

Follow-up to #2895 from its late review notes. The places-an-edit-keeps grid is now made without keeping a box per row, and its comments describe its memory and its contract as they are.

  • No box per row (row_boxes.rs): Grid::new walks the rows twice, once for the box they are all in and once to list each row's box. Before, it kept a box for every row while it worked, 32 bytes a row (about 320 MB for 10 million rows), at the first search after each edit. That list is gone. The cost is a second walk over the vertices.
  • Memory comment: the 256 by 256 cap bounds only the cell headers, about 1.5 MB. The comment now also says what grows with the rows: 4 bytes for each cell a row is listed in, at most 16 cells, usually one to four.
  • rows_touching doc: past u32::MAX rows every row is given, including rows without a shape. The doc said that never happens. Its only caller checks each row's shape and box, so nothing visible changes.

Internal only: no command, user guide or other surface changes. The grid tests pass unchanged.

Summary by CodeRabbit

  • Performance

    • Map grid construction now uses less temporary memory when processing shaped rows.
  • Documentation

    • Clarified that, in very large layers, results may include rows without shapes.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes

Grid::new computes the total extent and shaped-row count in a first pass, then recomputes row extents while populating the grid. The touching-row documentation now describes the possibility of shapeless rows in the fallback for indices beyond u32::MAX.

Grid extent and row selection

Layer / File(s) Summary
Grid construction and touching-row behavior
crates/map/src/row_boxes.rs, crates/map/src/lib.rs
Grid construction no longer retains a per-row extent vector. It recomputes row extents during grid population. The documentation notes that shapeless rows may be included in the beyond-u32::MAX fallback.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related PRs

Suggested reviewers: giswqs, mavrick-f

Merge Risk: Minimal · up to 1133c

This change lowers peak memory when the grid is first built after an edit, at the cost of an extra pass over the row vertices. It also corrects the documentation of the beyond-u32::MAX fallback. No behavior change or merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change to the held-places grid, which the summary and objectives describe: Grid::new no longer keeps a per-row box list. It also names the fix type and the ticket reference. The ti…
Description check Passed The description covers the change and its reasoning. It explains the two-pass Grid::new, the memory cost removed, the revised memory comment, and the rows_touching doc correction. It states that no vi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change to the held-places grid, which the summary and objectives describe: Grid::new no longer keeps a per-row box list. It also names the fix type and the ticket reference. The title is specific, but it uses jargon ("held-places grid", "C2f-6") and does not name the main effect, which is removing per-row box storage. The title is related to the changeset and does not fail.

Full details: Description check

Explanation

The description covers the change and its reasoning. It explains the two-pass Grid::new, the memory cost removed, the revised memory comment, and the rows_touching doc correction. It states that no visible UI change exists, which matches the template. The Testing section says the grid tests pass unchanged, but it does not name a command. The Related issue section cites Refs #2032 and a follow-up to #2895. The UI evidence section is correctly marked as having no visible change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the grid at dawn
One pass counts the shaped rows
The next sets boxes in their place
A note marks the large-index case
Then off I hop through fields of green

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d7c3b01a-8316-428a-8f92-5c5f522b68d4
Commits

Reviewing files that changed from the base of the PR and between f5cf513 and 1133c94.

Files selected for processing: 2

  • crates/map/src/lib.rs
  • crates/map/src/row_boxes.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Comment on lines +138 to 140
/// 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.

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.

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
/// 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.
/// 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.

Category: quality

Copy link
Copy Markdown
Contributor Author

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 rewrap goes into the next C2f PR.

Copy link
Copy Markdown
Contributor Author

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.

Comment on lines +46 to +49
/// 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.

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.

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 growing Vec keeps 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 with cargo xtask memory and state the number. This matters because the comment is the place that records the grid's cost against the layer size.

Category: quality

Copy link
Copy Markdown
Contributor Author

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".

Copy link
Copy Markdown
Contributor Author

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.

Comment on lines +54 to +61
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;
}
}

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.

This removes the 32-byte-per-row box list, but the grid is still built synchronously from held_places (crates/engine/src/cmd/design.rs:1474), which runs inside edit commands. Every row's geometry and extent are now computed twice on the first search after an edit, and the cell sizes need the total box before the second walk can start, so the second walk can't be avoided with this layout. The PR says so, and the trade-off is reasonable for a 10 million row layer. It would still be worth timing the first search after an edit on a large layer, before and after, so the cost is known rather than estimated. Confidence is medium-low, since the per-row extent is cheap and the real cost depends on vertex counts.

Category: performance

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 Geometry::extent per row, which is also what held_places did on every command before #2895. So the first search after an edit costs about two of the old per-command scans, and later searches cost nothing until the rows change. Timing it on a large layer is worth doing once the edited layer's grid is updated in place rather than rebuilt, which is noted for #2032.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the diff, the two changed files, the grid tests, Features::geometry (a borrow, so the second walk clones nothing), and the caller in held_places. I found no correctness bugs. The rewrite keeps the same total, shaped and cell logic. The beyond path, the empty-box handling and the lock handling are unchanged.

Bugs: None found. I checked that the two-walk build gives the same grid as before, that the u32::try_from cutoff and the beyond fallback behave as the new rows_touching doc says, and that the existing grid tests cover the changed build path.

Security: None found. No unwrap, expect or unsafe was added, and no input handling changed.

Performance:

  • The grid build now walks every row's geometry twice, once for the total box and once to list rows. The cell size needs the total, so the second walk can't be avoided with this layout. The trade-off is 32 bytes saved per row against a second walk. The grid is built synchronously in held_places (crates/engine/src/cmd/design.rs:1474), so the first search after an edit gets slower. Confidence: medium-low. I suggest timing it on a large layer before and after. (Inline comment posted.)

Quality:

  • The rewrapped Cache::touching doc comment has a line of about 140 characters and an orphan "change." line. A suggestion block is attached. (Inline comment posted.)
  • The memory comment says "4 bytes a cell" and "usually one to four" cells. Vec<u32> spare capacity makes the real figure higher, and the "usually" claim isn't measured here. (Inline comment posted.) Confidence: high.
  • Nit: let e = &box_of(i); in the second loop could be let e = box_of(i); with grid.span(&e).

AGENTS.md:

  • "Size for real data" asks a PR that changes what a layer's grid stores to state what it holds as a multiple of the layer, as cargo xtask memory measures. The PR body gives the saving (about 320 MB for 10 million rows) but not the grid's own size as a multiple of the layer. Confidence: medium. I raised it here and did not post it inline, because it's about the PR description.

Already raised by earlier reviews: 0. There were no prior review threads on this PR.

Change size

Compared with the base branch: the whole PR against main (merge base f5cf513 to PR head 1133c94).

Files changed Added Modified Removed Renamed Size before Size after Total change
2 0 2 0 0 255.8 KB 256.2 KB +343 B
Path Size before Size after Size change
crates/map/src/lib.rs 244.9 KB 245.0 KB +71 B
crates/map/src/row_boxes.rs 10.9 KB 11.1 KB +272 B

@pick2510
pick2510 enabled auto-merge November 25, 2026 11:58
@pick2510
pick2510 added this pull request to the merge queue Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2906/
Web app https://preview.rustgis.app/pr-2906/app/
Commit 1133c94

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

Merged via the queue into opengeos:main with commit 1994173 Nov 25, 2026
28 checks passed
@pick2510
pick2510 deleted the crs-held-index-2 branch November 25, 2026 12:23
MikeFTV pushed a commit to MikeFTV/RustGIS that referenced this pull request Nov 26, 2026
… a map in its system written as placed (C2f-7 part 2) (opengeos#3018)

* feat(edit): vertex handles in the map's coordinates; on a map in the layer's own system edits are written as placed (C2f-7 part 2)

Edit Vertices puts each selected feature where the map draws it (Flat::held), not through
longitude/latitude: on a map in the layer's own system the handles are its stored coordinates, a
dragged vertex is written there as placed (edit.vertex / edit.moveSharedVertex x, y), and a
feature with no longitude/latitude place gets handles. Deleting a vertex edits the stored
geometry. The globe keeps longitude/latitude; snapped vertices go by longitude/latitude so the
place snapped to stays as stored.

Carried over: split_own doc, edit.trace params and editing.md wrap (opengeos#2900), row_boxes docs
(opengeos#2906).

* fix(edit): a snapped vertex is committed at the longitude/latitude it snapped to; a release with no place is said

From the pre-push review: the snapped place now goes to the command as snapping gave it, not
after a round trip through the map's coordinates (inexact on Web Mercator for lon/lat layers).
A release where the map's coordinates have no longitude/latitude says so. A null lon/lat beside
x/y is no place. edit.moveSharedVertex x/y documented and tested; projection hashed directly.

* test(edit): integration tests read a drag's place through VertexDrag::lonlat

VertexDrag::at is in view coordinates now; VertexDrag::lonlat gives the longitude/latitude a
release commits (where it snapped, else the pointer's place).

* docs(edit): VertexDrag::lonlat says what a release writes; the snap test asserts its place doesn't round-trip

* fix(edit): drags cancel on a projection change; snapped moves on features with no lon/lat; half lon/lat pairs refused; release notice tested

* test(edit): a lon/lat vertex move on a feature with no lon/lat place is written in its own coordinates
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.

1 participant