Skip to content

fix(layout): read each layer once for the statistics of all of a publication's texts - #3634

Merged
jgregoriorincon merged 1 commit into
opengeos:mainfrom
jgregoriorincon:perf/3132-statistic-passes
Dec 3, 2026
Merged

jgregoriorincon merged 1 commit into
opengeos:mainfrom
jgregoriorincon:perf/3132-statistic-passes

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

layout.publication read a layer once for each text holding one of its statistics ({count:Layer}, {sum:Layer:field}…), twice over: to measure the texts and to say which figures they miss. Both now gather the tokens of all the texts first, so each of the two reads a layer once, however many texts name it.

  • statistic_figures works out the figures of all the texts together.
  • statistic_notices_each (new) gives each text's notices from one set of figures; say_layout_text_statistics calls it, so importing a layout and changing the first frame's map read once too. The notices and their order are unchanged.
  • Tokens are deduplicated and grouped by layer through hashed lookups, as the list now spans every text of a layout.

The change is in the engine and the renderer, so the desktop app, the browser, the command line, Python, the phone, the Assistant and MCP all get it through the same commands; no command, parameter or saved data changes, so there is nothing new to undo.

Measuring and the notices remain two separate passes. Drawing a layout still reads text by text; that is outside this command.

Testing

  • New tests in crates/render/src/layout/tests/statistic_passes.rs count the passes over a layer; three of them failed before the change (5 and 4 passes where 1 and 2 are expected).
  • Counted layer_statistics calls under a debugger for rustgis-cli run --sample --cmd layout.publication=…: on main, 2 with one text holding {count:Countries} and 10 with five; with this change, 2 in both.
  • checks.sh: fmt, clippy, doctests, layers and schema --check pass. nextest: 12353 of 12365 pass. The 12 failures are in rustgis-geolibre (7), rustgis-ui-egui's smoke test (1), and four map frame tests of rustgis-ui-egui; those four fail the same way on main (c4cc3d9) on this machine, and none touches the code changed here.

UI evidence

No visible UI change.

Related issue

Closes #3132

Summary by CodeRabbit

  • Improvements
    • Layout text statistics now avoid repeated work when multiple texts reference the same layer.
    • Notices continue to be reported for each text, including when maps are missing or unavailable.
  • Tests
    • Added coverage for shared layer processing, per-text notices, and layouts with no referenced layers.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Layout text statistics now calculate figures across multiple texts and avoid repeating calculations for tokens that reference the same layer. The layout command requests per-text notices in one call, and tests verify pass counts and notice results.

Changes: Layout text statistics

Layer / File(s) Summary
Batch token and figure calculation
crates/render/src/layout/dynamic_text.rs
The notice API accepts multiple texts, deduplicates statistic tokens, and calculates figures once per referenced layer. It returns notices for each text.
Layout command integration and validation
crates/engine/src/cmd/layout/text.rs, crates/render/src/layout/dynamic_text.rs, crates/render/src/layout/tests.rs, crates/render/src/layout/tests/statistic_passes.rs
The layout command collects text contents and warns on returned notices. Tests check layer pass counts, token order, per-text notices, and cases with no usable map.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • opengeos/RustGIS#2853 — Defines the layer-statistic tokens that this change processes across layout texts.

Possibly related PRs

  • opengeos/RustGIS#2980: Introduced the layer-statistic tokens and figure computation that this change updates.
  • opengeos/RustGIS#3073: Established the layout module structure used by the added statistic-pass tests.

Suggested reviewers: giswqs, mavrick-f

Merge Risk: Minimal · up to ea1c3

This change reduces repeated layer reads when computing layout text statistics. Commands, parameters, and saved data are 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: layout.publication now reads each layer once for the statistics of all of a publication's texts. It matches the summary, the objectives, and the linked issue #3132. Th…
Description check Passed The description follows the template. It has a Summary that explains the change and why. It has a Testing section with new tests, debugger counts, and checks.sh and nextest results. The UI evidence se…
Linked Issues check Passed [#3132] The issue requires one layer pass across all texts that name the same layer, for layout.publication. The reviewed head changes distinct_stat_tokens in `crates/render/src/layout/dynamic_tex…
Out of Scope Changes check Passed All changed code serves the fix for #3132. The changes are: (1) figures_of and distinct_stat_tokens now work across texts, which is the core fix; (2) statistic_notices_each is a new public funct…
Full details: Title check

Explanation

The title names the main change: layout.publication now reads each layer once for the statistics of all of a publication's texts. It matches the summary, the objectives, and the linked issue #3132. The fix(layout) prefix fits a bug fix. The title is 84 characters, a little long, but it is specific and clear.

Full details: Description check

Explanation

The description follows the template. It has a Summary that explains the change and why. It has a Testing section with new tests, debugger counts, and checks.sh and nextest results. The UI evidence section states 'No visible UI change.', which the template allows. It has a Related issue section that closes #3132. The description is complete and specific.

Full details: Linked Issues check

Explanation

[#3132] The issue requires one layer pass across all texts that name the same layer, for layout.publication. The reviewed head changes distinct_stat_tokens in crates/render/src/layout/dynamic_text.rs to take all texts at once and deduplicate tokens across them. statistic_figures now calls figures_of once over that combined token list. figures_of groups tokens by lowercased layer name and calls rustgis_map::layout::layer_statistics once per group, with the PASSES test counter recording each group pass. Because one call covers every text, each layer is read once per publication measurement. The notice path (notices_over) gathers tokens across texts too, computes one figures_of call, and then reuses the figures per text through statistic_notices_each, so the notices pass also reads each layer once. Evidence limits: the diff for crates/engine/src/cmd/layout/text.rs could not be read, so the wiring of say_layout_text_statistics is not verified from source. The new tests and the debugger pass counts are author-reported and were not re-run here. The render-level change alone covers the acceptance criterion.

Full details: Out of Scope Changes check

Explanation

All changed code serves the fix for #3132. The changes are: (1) figures_of and distinct_stat_tokens now work across texts, which is the core fix; (2) statistic_notices_each is a new public function that shares one figure set across texts, which the PR summary and the say_layout_text_statistics change in crates/engine/src/cmd/layout/text.rs use for the notice pass, a second read of the same layers; (3) statistic_notices, map_statistic_notices and statistics delegate to the shared logic with unchanged behavior for one text; (4) #[cfg(test)] pass counter and the statistic_passes test module support verification of the fix. No unrelated feature or behavior change was found in the reviewed render diff. The engine diff could not be read, so its exact content is unverified, but its described purpose is the same notice-pass consolidation.

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 gathers tokens from each page,
One layer pass replaces many a gauge.
The notices return to text in line,
While title, note, and source align.
The rabbit thumps: “Each figure’s fine!”

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: 0cb8f953-03b8-4e5d-9018-9d10db96bdd1
Commits

Reviewing files that changed from the base of the PR and between c4cc3d9 and ea1c3ef.

Files selected for processing: 4

  • crates/engine/src/cmd/layout/text.rs
  • crates/render/src/layout/dynamic_text.rs
  • crates/render/src/layout/tests.rs
  • crates/render/src/layout/tests/statistic_passes.rs

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

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3634/
Web app https://preview.rustgis.app/pr-3634/app/
Commit ea1c3ef

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

@jgregoriorincon
jgregoriorincon marked this pull request as ready for review December 3, 2026 01:27
@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Dec 3, 2026
Merged via the queue into opengeos:main with commit 72dd3f8 Dec 3, 2026
27 checks passed
@jgregoriorincon
jgregoriorincon deleted the perf/3132-statistic-passes branch December 3, 2026 02:04
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.

[Bug]: layout.publication reads a layer once for each text that holds one of its statistics

1 participant