Skip to content

Speed up finding settings by name - #12237

Open
error414 wants to merge 1 commit into
iNavFlight:next-10.1from
error414:error414/fix/setting-find-by-name
Open

error414 wants to merge 1 commit into
iNavFlight:next-10.1from
error414:error414/fix/setting-find-by-name

Conversation

@error414

@error414 error414 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Finding settings by name uses index table and dictionary. Current solution is when configurator ask for settings for example for gps_sat, inav walks through index table and from dictionary create setting name and after stah uses strcmp. It's slow because ibnav have to create setting name for each record in index table.

Correct solution is create index record from name which came from configurator and then just comapre indexes.

The old solution is as slow that even on H7 CPU it makes gaps in dshot frames.

Before

{32, 225, 1, 20, 14, 0, 0} -> "gyro_main_lpf_hz" strcmp "gyro_main_lpf_hz" 

After

"gyro_main_lpf_hz" -> {32, 225, 1, 20, 14, 0, 0}
{32, 225, 1, 20, 14, 0, 0} memcmp {32, 225, 1, 20, 14, 0, 0} 

@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

qodo-free-for-open-source-projects Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Speed up settings lookup by comparing encoded names

🐞 Bug fix ✨ Enhancement 🕐 20-40 Minutes

Grey Divider

AI Description

• Encode requested setting names instead of decoding every stored name during lookup.
• Try both split-word and whole-name encodings to support existing generated settings.
• Reduce lookup stalls that can disrupt time-sensitive flight-control work.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed lookup is called by MSP setting commands and controls the single end-to-end integration behavior of locating, reading, writing, and describing a named flight-controller setting.
  • The settings table is an implementation boundary within that integration, not an independent capability.
  • Reads, writes, and metadata lookup all traverse the same named-setting integration.
  • A wrong table entry is an incorrect outcome within that bounded integration, not an independent storage or flight-control capability.
Behavioral complexity 🟡 Medium 🧩 Data transformation, Compatibility cases

  • Before, settingFind decoded each stored setting name and compared the resulting string.
  • After, the request is transformed into the generator's packed word-index representation and compared byte-for-byte.
  • The new correctness condition is that runtime word lookup, underscore splitting, zero padding, and index encoding must exactly reproduce the generator for both byte-indexed and variable-length-index configurations; the two split modes must also select the same representation as generation.
  • This is a changed transformation and compatibility condition, not merely reuse of existing mapping infrastructure.
Potential damage 🟡 Medium 🩹 Temporary loss

  • The concrete impact is loss of named MSP setting access for affected names.
  • A failed lookup does not itself modify persistent state because the caller rejects a NULL setting before reading or writing it.
  • The capability is recoverable by retrying with a correctly resolved name or reverting firmware; no automatic retry or repair worker was found or is required for this failure mode.
  • Reversible at the code level by firmware rollback or correction.
  • Runtime recovery is a retry/reconnect or use of index-based access where supported; no persistent-state repair or external compensation is required for a rejected request.
Assessed commit bd6b505
Diagram

graph TD
  A["MSP setting name"] --> B["Encode candidate"] --> C["Packed word dictionary"] --> D["Scan encoded names"] --> F["Setting or null"]
  E["Settings table"] --> D
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Generate a direct name lookup table
  • ➕ Could avoid scanning all settings for each request.
  • ➖ Requires generator changes and additional persistent storage or code in firmware.

Recommendation: The proposed approach is a good fit for a memory-constrained firmware fix: it reuses generated encodings and removes repeated name reconstruction without changing the settings format. A generated direct lookup is worth considering only if encoded-table scanning remains a measured bottleneck.

Files changed (1) +92 / -6

Enhancement (1) +92 / -6
settings.cMatch requested names against stored setting encodings +92/-6

Match requested names against stored setting encodings

• Adds a packed-dictionary word lookup and encodes requested names in the generator’s split-word or whole-name format. 'settingFind' now compares those bytes against stored setting records rather than decoding every record into a string.

src/main/fc/settings.c

@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 reply 'qodo' on any finding to push back, ask questions, or dig deeper

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

RAM / Flash usage vs. base commit 01a7aa3 — commit bd6b505

Using the nearest available size baseline: this build contains base commit 6cbfc64, which has no stored baseline yet, so the deltas also include what was merged to the base since 01a7aa3.

Target Flash Δ RAM Δ
MATEKF405 ⚠️ +4176 B (+0.58%) CCM: -4 B (-0.01%)
RAM: +1660 B (+1.59%)
MATEKF722 +1520 B (+0.32%) ITCM_RAM: -928 B (-7.40%)
RAM: +64 B (+0.07%)
TCM: ±0 B (±0.00%)
MATEKF765 +1800 B (+0.24%) DTCM_RAM: ±0 B (±0.00%)
SRAM1: +64 B (+0.05%)
MATEKH743 ⚠️ +7636 B (+0.95%) D2_RAM: +256 B (+7.84%)
DTCM_RAM: ±0 B (±0.00%)
ITCM_RAM: -888 B (-5.41%)
RAM: +1940 B (+1.36%)

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

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Test firmware build ready — commit bd6b505

Download firmware for PR #12237

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

@error414
error414 changed the base branch from maintenance-10.x to next-10.1 November 18, 2026 21:38
@error414
error414 force-pushed the error414/fix/setting-find-by-name branch from dedfb40 to bd6b505 Compare November 18, 2026 21:40
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