Skip to content

perf(map): a level the display copy found saves too little isn't thinned again - #3013

Merged
Mavrick-F merged 1 commit into
opengeos:mainfrom
Mavrick-F:perf/refused-lod-level
Nov 26, 2026
Merged

Mavrick-F merged 1 commit into
opengeos:mainfrom
Mavrick-F:perf/refused-lod-level

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

When a layer is drawn zoomed in on Web Mercator, it first tries to build a display copy at the view's level. If that copy drops fewer than MIN_SAVING of the vertices, it is refused. The exact path then built the same level again from the same rows (lod::project_budgeted) and threw it away for the same reason. That is a second pass over the whole layer for nothing.

Now lod::display returns why it made no level (Refused::Unfit or Refused::SavesTooLittle), and the layer keeps that reason with the refused attempt. When the exact path finds that the attempt for the same geometry revision, level and row count saved too little, it skips the copy and draws the full projection, as it did before after the second build was refused. This only applies to longitude/latitude rows on Web Mercator, where both builds count their saving against the same vertices.

The drawn picture doesn't change: in both cases the full projection is drawn.

Timing

This is the benchmark's render_view case from #1227: 100,000 buildings from polygons.gpkg, a view of downtown Nashville, share.exportMap to PNG. Each figure is the median of interleaved runs of the whole rustgis-cli run through the host queue, against main with #3008, on a shared box.

Case Wall, before → after CPU
Loaded layer 0.501 → 0.494 s 13–16% less
Streamed layer 0.665 → 0.559 s 13–16% less

In a profile of the loaded case, the discarded copy was about 0.05 s of the 0.12 s spent thinning and projecting. The loaded case's wall time barely moves, because that step overlaps with others there.

Memory

Nothing new is held. Each refused attempt keeps a small enum alongside it, in the existing list of LEVELS_KEPT entries.

Surfaces

The change is in rustgis-map's display levels, so it reaches every place that draws a vector layer on a flat Web Mercator map: the desktop app, the browser, the phone, and map export from the command line, Python and the Assistant. No command, parameter or saved file changes.

Testing

  • rejected_display_levels_are_not_rebuilt_on_unchanged_frames (extended in crates/map/src/lib.rs): it checks that the refused level is built only once and that the full projection is drawn. It also checks that a level no display attempt refused is still built by thinned_in. It fails without the fix.
  • The existing lod and Layer tests, updated for Result in place of Option.
  • cargo fmt --all --check, and the full gate on the fork's CI on this commit.

UI evidence

No visible UI change.

Related issue

Part of #1227.

Summary by CodeRabbit

  • Bug Fixes
    • Map layers now avoid rebuilding a reduced-detail copy when it would not meaningfully reduce geometry size, while continuing to display the full projected geometry.
    • Failed display-building attempts are handled consistently, and levels that can be built remain available.

…ned again (opengeos#1227)

A layer drawn zoomed in on Web Mercator first tries a display copy at the view's
level. When that copy drops too few vertices it is refused, and the exact path
then built the same level again from the same rows, only to refuse it for the
same reason: a second pass over the whole layer for nothing. The display
attempt now says why it made no level, and the exact path skips a level it
found saves too little.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Display attempts now return specific refusal reasons. The map layer records those reasons and avoids rebuilding a matching LOD copy when the attempt was refused for insufficient savings. Tests cover refused and unrefused levels.

Changes: LOD refusal reuse

Layer / File(s) Summary
Classify display outcomes
crates/map/src/lod.rs
lod::display now returns Result<Display, Refused>. It reports Unfit for ineligible or unbuildable attempts and SavesTooLittle(rows) when savings are insufficient.
Record and reuse refusals
crates/map/src/lib.rs, crates/map/src/lod.rs
prepare_display records refusal reasons. thinned_in skips a matching build refused for insufficient savings. Tests check rejection handling and verify that refused levels are not rebuilt while unrefused levels can be built.

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

Change: Refactor

Possibly related PRs

  • opengeos/RustGIS#1120: Adds a bounded cache for accepted display levels and rejected attempts, which is related to this PR’s display-refusal tracking.

Suggested reviewers: pick2510, giswqs

Merge Risk: Minimal · up to e46ad

This change avoids rebuilding a display level that was already refused for saving too few vertices. The drawn output is unchanged. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a display level that was already refused for saving too little is no longer rebuilt. It uses the perf(map) prefix and matches the summary, the lod.rs Refused change, a…
Description check Passed The description follows the template. It has Summary, Testing, UI evidence, and Related issue sections. The UI evidence section keeps the 'No visible UI change.' line, as the template requires. The Su…
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 main change: a display level that was already refused for saving too little is no longer rebuilt. It uses the perf(map) prefix and matches the summary, the lod.rs Refused change, and the lib.rs skip logic. The wording is slightly awkward but specific enough for a reviewer scanning history.

Full details: Description check

Explanation

The description follows the template. It has Summary, Testing, UI evidence, and Related issue sections. The UI evidence section keeps the 'No visible UI change.' line, as the template requires. The Summary explains the problem, the fix, and the scope. Testing names the new and updated tests and the CI gate. Related issue links Part of #1227. The timing and memory details go beyond the template but add useful context.

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 map with care
A refused level waits right there
Too little savings? Skip the copy
The full projection stays in view
The rabbit hops through LOD anew

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: e6984364-3a6f-4a41-b2ae-18371745fdbf
Commits

Reviewing files that changed from the base of the PR and between 309ff9d and e46ad43.

Files selected for processing: 2

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

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

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff (crates/map/src/lib.rs, crates/map/src/lod.rs), the surrounding prepare_display, thinned_in, display and project_budgeted code, and the Flat::project path. There are no prior review threads, so nothing was deduplicated.

I found no bugs, security issues or performance regressions. The change does what the PR says, with one nit posted inline.

Bugs

  • None found.
  • Checked: skipping the copy in thinned_in when a refused display attempt has SavesTooLittle matches what the copy path would have done. Flat::project uses map_coords, so vertex counts match between all in thinned_in (from self.projected) and all in display (from the source features). The budget and whole_layer_eligible differences only change None outcomes, which the skip also returns. Confidence: high.

Security

  • None found.

Performance

  • None found. The change removes one redundant full-layer projection on the zoomed-in Web Mercator path. It adds only a small Copy enum per refused attempt, bounded by LEVELS_KEPT.

Quality

  • crates/map/src/lod.rs:119: the display doc does not say what Err means now. I suggested wording (inline). Confidence: high. Category: quality.

AGENTS.md

  • None found. Changed signatures have no new unwrap/expect, no std::time, no new threads, no new commands or saved fields, and no new limits to ratchet. The PR body states the surfaces reached.

Change size

Compared: the whole PR against main (merge base dde41e0 to PR head e46ad43).

Measure Value
Files changed 2 (added 0, modified 2, removed 0, renamed 0)
Size before 287.6 KB
Size after 289.9 KB
Total size change +2.3 KB
Path Before After Change
crates/map/src/lib.rs 245.0 KB 246.5 KB +1.5 KB
crates/map/src/lod.rs 42.6 KB 43.4 KB +782 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3013/
Web app https://preview.rustgis.app/pr-3013/app/
Commit e46ad43

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

@Mavrick-F
Mavrick-F added this pull request to the merge queue Nov 26, 2026
Merged via the queue into opengeos:main with commit 5a6dd3b Nov 26, 2026
28 checks passed
@Mavrick-F
Mavrick-F deleted the perf/refused-lod-level branch November 26, 2026 07:03
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