Skip to content

perf(tiles): fill a window's gaps a tile at a time while its tiles load - #3547

Merged
Mavrick-F merged 1 commit into
opengeos:mainfrom
Mavrick-F:perf/stand-in-2761
Dec 1, 2026
Merged

Mavrick-F merged 1 commit into
opengeos:mainfrom
Mavrick-F:perf/stand-in-2761

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

While a raster read in place waits for its tiles, the other levels kept stand in for them (stand_in). Every missing pixel looked its tile up at every other level, in every band, at each redraw, even at levels with nothing kept. On a 2560 × 1440 view of a 10.6 GB file, more than half of the draw was spent there, though the tiles themselves had arrived in the first 0.3 s.

Each row of a gap is now split into the runs of pixels that share a tile of the other level. A tile is looked up once a run, and a run whose tile isn't kept is passed over whole. The picture is the same: a pixel's place in the other level is worked out as before, and no-data, short tiles and which level fills a pixel behave as they did.

Not in this PR: redraws as tiles land still run on the UI thread on a map without tile layers, and the window is still assembled whole each time. Both are later steps of #2761.

Surfaces: every one that draws a raster read in place (desktop, browser, command line, Python, phone). No command, parameter, saved format or undo step changes. Memory: one u32 a column of the gap being filled.

Testing

  • stand_ins_take_each_pixel_from_the_nearest_level_kept: 3 windows × 40 patterns of kept tiles, levels that don't halve evenly and tiles of different sizes, each pixel against a lookup of its own.
  • share.exportMap of a local 83517 × 78739 LZW file, three runs each, v0.9.0 against this branch, on a busy machine, seconds:
Size Scale v0.9.0 This branch
1920 × 1080 1:3,000,000 4.64–5.13 2.56–3.25
1920 × 1080 1:400,000 6.66–9.83 2.75–4.16
2560 × 1440 1:3,000,000 4.81–6.53 2.63–3.43
2560 × 1440 1:400,000 6.27–7.02 3.16–4.06
3508 × 2480 1:3,000,000 7.30–8.17 4.69–5.93
3508 × 2480 1:400,000 4.45–8.21 1.03–4.36

The PNGs were byte for byte the same in all six. The last fix of review (a tile shorter than its header says) came after these runs.

  • Full CI passed on this commit in the fork.

UI evidence

No visible UI change.

Related issue

Part of #2761.

Summary by CodeRabbit

  • Bug Fixes
    • Improved filling of missing raster values across differing tile sizes and boundaries, while preserving nearest-level lookup behavior.
    • Empty values remain unchanged when no usable value is available from another level.

While a raster read in place waits for its tiles, the other levels kept stand
in for them. Each missing pixel looked its tile up at every other level, also
at levels with nothing kept, at every redraw. A level's tile is now looked up
once for the run of pixels in it, and passed over whole when it isn't kept.
The picture is the same. Part of opengeos#2761.
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

stand_in now groups gap columns that map to the same tile in another level. For each row, it reads tile data for runs with empty pixels and fills those pixels. A new test compares the results with per-pixel nearest-level lookup across varied level sizes and kept-tile sets.

Changes: Raster stand-in filling

Layer / File(s) Summary
Group mapped columns and fill empty pixels
crates/tiles/src/cog/raster.rs
stand_in groups columns by destination tile and reads each needed tile row for a run. It fills only NaN pixels and preserves existing handling of missing data. A new test compares results with per-pixel nearest-level lookup across uneven dimensions, tile sizes, target levels, and kept-tile sets.

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

Change: Refactor

Suggested reviewers: siiinc

Merge Risk: Minimal · up to ff02e

This change speeds up filling gaps while raster tiles load, and it is meant to leave the output unchanged. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a performance fix in tile gap filling (stand_in) that processes gaps a tile at a time while tiles load. It uses a conventional type(scope) prefix and is specific enoug…
Description check Passed The description follows the template. It has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the change and rationale. Testing names a new test and gives benchmark tabl…
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 performance fix in tile gap filling (stand_in) that processes gaps a tile at a time while tiles load. It uses a conventional type(scope) prefix and is specific enough for a reviewer scanning history. The title is not vague, and the changeset matches it.

Full details: Description check

Explanation

The description follows the template. It has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the change and rationale. Testing names a new test and gives benchmark tables. UI evidence keeps the 'No visible UI change.' line as the template requires. Related issue links Part of #2761. The template's Testing example mentions cargo xtask ci, and the author reports full CI passed in the fork, so the section is complete.

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 maps each column run,
Then checks the tile rows one by one.
Empty pixels find their place,
Kept tiles lend a value’s grace.
Across uneven levels they go,
And match the nearest lookup flow.

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: 0dcceb38-f914-46d5-8fbf-5cbc7adcd4e9
Commits

Reviewing files that changed from the base of the PR and between ab8a812 and ff02e11.

Files selected for processing: 1

  • crates/tiles/src/cog/raster.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.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Code review

Reviewed crates/tiles/src/cog/raster.rs (the stand_in rewrite and its new test). I did not compile or run the test, since I have no shell here. The findings below come from reading the diff against the surrounding code.

Bugs: None found.

I checked these paths and they hold:

  • Run splitting: chunk_by groups the level's columns by tile, and the columns are monotonic, so each run is contiguous and lines up with the destination offset.
  • Offset arithmetic: g.cols.0 >= cols.0 always holds, because assemble clamps gap starts to max(tx * tw, cols.0), so g.cols.0 - cols.0 cannot underflow.
  • Short tiles: plane.get(row..) and line.get(ox % tw) report short only for pixels still NaN, which matches the old per-pixel behaviour. A run is skipped whole only when it has no NaN pixels.
  • Missing tiles: a run whose chunk isn't kept sets short and moves on, as before.
  • Caching: found caches kept(o, c) per level, including None, so the per-chunk lookup happens once. It is also no longer cloned.
  • Test: the expected-value derivation uses the same level order as others, the same (v + 0.5) * to / from mapping and the same tile index. Bit comparison is sound because every NaN is f32::NAN.

Security: None found. Hostile header values are handled as before: tw and th are clamped with .max(1), and the lookups use get.

Performance: No concerns. The change removes the per-pixel lookup and clone. The new per-gap columns Vec holds one u32 per gap column and is bounded by the window width, which is capped by WINDOW_SAMPLES. The PR body already states this.

Quality: Nothing worth posting inline. The new test's doc comment and the stand_in comments match the code.

AGENTS.md: No violations found in the changed lines.

  • No unwrap, expect or indexing was added.
  • The test has no timer waits and no identical assert_eq! sides.
  • The PR body covers the surfaces it reaches and the undo story.
  • This change adds no command, parameter, saved format or layer copy, so the cancellation lists, schema and memory-limit rules don't apply.
  • The UI-thread redraw cost is pre-existing and the PR says it is a later step of A large local GeoTIFF is drawn from one overview at every zoom, blurred zoomed in #2761.

Twins: The PR changes only the stand_in path inside window(). I checked the other callers of stand_in and assemble in this file and found no sibling that needs the same change. Other read routes are not affected because stand_in is private to this module.

Confidence: High that the change is correct as written. Medium-high on the test passing, since I could not run it.

Already raised earlier: 0. prior-reviews.json has no threads.

Change size

Compared with main (merge base def6c67 to PR head ff02e11).

Files changed Added Modified Removed Renamed
1 0 1 0 0
Size before Size after Total size change
38.1 KB 41.2 KB +3.1 KB
Path Size before Size after Size change
crates/tiles/src/cog/raster.rs 38.1 KB 41.2 KB +3.1 KB

@Mavrick-F
Mavrick-F added this pull request to the merge queue Dec 1, 2026
@Mavrick-F
Mavrick-F removed this pull request from the merge queue due to a manual request Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3547/
Web app https://preview.rustgis.app/pr-3547/app/
Commit ff02e11

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 Dec 1, 2026
Merged via the queue into opengeos:main with commit 0fb3e2a Dec 1, 2026
30 of 32 checks passed
@Mavrick-F
Mavrick-F deleted the perf/stand-in-2761 branch December 1, 2026 19:28
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