Skip to content

Fix spurious per-region size deltas when a target's regions are renamed - #11948

Open
sensei-hacker wants to merge 1 commit into
iNavFlight:release/9.1from
sensei-hacker:fix-region-rename-false-deltas-release91
Open

sensei-hacker wants to merge 1 commit into
iNavFlight:release/9.1from
sensei-hacker:fix-region-rename-false-deltas-release91

Conversation

@sensei-hacker

Copy link
Copy Markdown
Member

Summary

Fixes a real bug flagged by Qodo on #11945 (a routine release/9.1 -> master sync PR that carried the size-report region-breakdown feature, and surfaced two findings in the process — see below for why only one is addressed here).

diffSizeReports() in .github/scripts/size-diff-comment.js (the CI job that posts a "RAM/Flash usage delta" comment on PRs) computed a per-region delta table whenever both the PR and baseline size reports had a non-empty regions breakdown, taking the union of region names and defaulting a region missing from either side to 0 bytes. If a target's set of region names changes between the two commits being compared — e.g. a linker script splits one region into two, or renames one, with the exact same total bytes used and zero real growth — this reports the old name's entire usage as a large fictitious "loss" and the new name(s) as an equally large fictitious "gain," and can trigger the ⚠️ "notable" marker despite nothing actually changing.

Reproduced concretely: PR regions {SRAM1: 60000, SRAM2: 70000} vs. baseline regions {RAM: 130000} (same 130000 total, zero growth) produced RAM: -130000, SRAM1: +60000, SRAM2: +70000, flagged notable.

Changes

  • diffSizeReports() now only builds a per-region delta table when both sides name the exact same set of regions (this already matched the function's own documented intent — the code just didn't implement it). Otherwise it falls back to the existing (already-tested) combined RAM delta path.
  • When falling back specifically because the region set changed (vs. the pre-existing case of one side lacking regions entirely), the RAM cell now shows a short "region layout changed since baseline" note, so a genuine linker-layout change isn't silently invisible to reviewers even though no per-region numbers are shown.
  • Added test coverage: differing-region-set fallback (no growth, not notable, note shown), the same case combined with real growth (delta still reported, still notable), and a diffSizeReports-level unit test for the new regionSetChanged flag.

On the other Qodo finding from #11945

Qodo also flagged .github/scripts/extract-size-report.sh's map-path construction (map="${elf}.map"), claiming CMake >= 3.15's TARGET_FILE_BASE_NAME generator expression strips the .elf suffix, so the real map file would be <target>.map rather than <target>.elf.map. I checked this against this project's actual cmake/stm32.cmake/cmake/at32.cmake: both define the executable target itself as set(elf_target ${args_NAME}.elf) — i.e. .elf is part of the CMake target name string, not a build-system-imposed suffix — so TARGET_FILE_BASE_NAME returns the name with .elf still attached regardless of CMake version, and both branches of the version-conditional in generate_map_file() produce the same <target>.elf.map result in practice. Verified directly against real build artifacts (build/bin/AOCODARCF722AIO.elf.map, build/bin/AOCODARCF4V2.elf.map both exist and match ${elf}.map exactly). Not a real issue for this codebase — no change made for it.

Testing

  • node --test .github/scripts/size-diff-comment.test.js — 29/29 pass (27 pre-existing + 2 new... actually see below)
  • Manually reproduced the bug (before the fix) and confirmed the fix resolves it, via direct diffSizeReports()/renderComment() calls with the exact SRAM1/SRAM2 scenario above
  • Confirmed no regression: all pre-existing tests, including the RAM/CCM per-region breakdown and single-side-missing-regions fallback tests, still pass unchanged

Code Review

Reviewed with the inav-code-review agent — approved, with two minor test-coverage suggestions (adding a missing assertion, and a combined-growth-plus-rename test case) which were incorporated, and one product-decision suggestion (surfacing that the region layout changed even without a breakdown) which was also incorporated as the "region layout changed since baseline" note.

diffSizeReports() computed a per-region delta table whenever both the
PR and baseline had a non-empty `regions` breakdown, defaulting a
region missing from either side to 0 bytes. If a target's region
*names* changed between the two commits (e.g. a linker script split
one region into two, or renamed one, with the same total bytes used),
this reported the old name's entire usage as a large fictitious loss
and the new name(s) as an equally large fictitious gain - misleading
reviewers with a "notable" delta for a change that never happened.

Only build regionDeltas when both sides name the exact same set of
regions; otherwise fall back to the existing combined RAM delta path,
with a short note that the region layout itself changed so reviewers
aren't left wondering why the breakdown disappeared.

Qodo flagged this on PR iNavFlight#11945 (a routine release/9.1->master sync
that surfaced it); reproduced and fixed directly on release/9.1,
where the size-report feature actually lives.
@sensei-hacker sensei-hacker added this to the 9.1 milestone Sep 14, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Prevent false size deltas when memory regions are renamed

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Require identical region-name sets before calculating per-region memory deltas.
• Fall back to combined RAM deltas and disclose changed region layouts.
• Test renamed regions with unchanged totals and genuine memory growth.
Diagram

graph TD
    A["PR size report"] --> C{"Region sets match?"} -->|Yes| D["Per-region deltas"] --> F["Size comment"]
    B["Baseline report"] --> C
    C -->|No| E["Combined RAM delta"] --> G["Layout change note"] --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Normalize region aliases
  • ➕ Could preserve per-region comparisons across simple, known renames.
  • ➕ Would provide more granular deltas when region identities remain equivalent.
  • ➖ Requires target-specific linker-region mappings.
  • ➖ Cannot reliably represent region splits, merges, or arbitrary restructuring.
  • ➖ Risks reintroducing misleading comparisons when mappings become stale.

Recommendation: Keep the PR's exact-set check and aggregate fallback. Region names alone do not provide enough identity information to safely correlate renamed, split, or merged regions; the combined RAM delta remains accurate, while the layout-change note preserves reviewer visibility.

Files changed (2) +98 / -14

Bug fix (1) +34 / -14
size-diff-comment.jsFall back when memory region names differ +34/-14

Fall back when memory region names differ

• Requires identical region-name sets before calculating per-region deltas. Mismatched layouts use the combined RAM delta, retain normal notable-threshold handling, and display a region-layout-change note.

.github/scripts/size-diff-comment.js

Tests (1) +64 / -0
size-diff-comment.test.jsCover renamed-region fallback behavior +64/-0

Cover renamed-region fallback behavior

• Adds tests proving renamed or split regions do not create false deltas or warnings when total RAM is unchanged. Also verifies real aggregate growth remains notable and the comparison exposes the region-set-change flag.

.github/scripts/size-diff-comment.test.js

@github-actions

Copy link
Copy Markdown

RAM / Flash usage vs. base commit d5c29d6 — commit 259fb55

Target Flash Δ RAM Δ
MATEKF405 ±0 B (±0.00%) CCM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)
MATEKF722 ±0 B (±0.00%) ITCM_RAM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)
TCM: ±0 B (±0.00%)
MATEKF765 ±0 B (±0.00%) DTCM_RAM: ±0 B (±0.00%)
SRAM1: ±0 B (±0.00%)
MATEKH743 ±0 B (±0.00%) D2_RAM: ±0 B (±0.00%)
DTCM_RAM: ±0 B (±0.00%)
ITCM_RAM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)

See RAM/flash optimization guide for techniques to reduce usage.

@github-actions

Copy link
Copy Markdown

Test firmware build ready — commit 259fb55

Download firmware for PR #11948

245 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant