Skip to content

perf: replace repeated string.Contains with single-pass field parsing - #90

Open
g4dpz wants to merge 1 commit into
magicbug:mainfrom
g4dpz:optimise/flex-status-field-parsing
Open

perf: replace repeated string.Contains with single-pass field parsing#90
g4dpz wants to merge 1 commit into
magicbug:mainfrom
g4dpz:optimise/flex-status-field-parsing

Conversation

@g4dpz

@g4dpz g4dpz commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

ApplyStatusUnlocked previously called HasSliceField (which uses string.Contains with an interpolated string) up to 8 times per status message. This caused 8 string allocations + 8 full-string scans per radio update (~4 Hz during satellite tracking).

Changes

Replaced with ParsePresentFields: a single-pass tokeniser that builds a HashSet<string> of field names present in the status body, then all 7 field checks become O(1) lookups with zero per-field allocations.

Tests

6 unit tests added covering:

  • Typical slice status parsing
  • FM tone fields
  • Case-insensitive lookup
  • Tokens without equals sign (ignored)
  • Empty body
  • Extra whitespace handling

All 55 Flex tests pass.

@magicbug

magicbug commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Thanks for this — looks sensible, but it currently conflicts with main (mainly OscarWatch/Rig/FlexSmartSdrClient.cs, which has moved on since the branch was cut — e.g. pan/PanStreamId handling).

Please rebase or merge main and resolve the conflict so this can be reviewed/merged. Happy to take another look once it is clean.

ApplyStatusUnlocked previously called HasSliceField (string.Contains
with interpolated string) up to 8 times per status message, causing
8 string allocations + 8 full scans per radio update (~4 Hz).

Replace with ParsePresentFields: a single-pass tokeniser that builds
a HashSet<string> of field names present in the status body, then all
7 field checks become O(1) lookups with zero per-field allocations.

Note: upstream has added PanStreamId/pan handling since this branch
was cut. The ParsePresentFields approach can also replace HasPanField
for the pan status messages — happy to add that in a follow-up once
this merges.

Includes 6 unit tests covering typical status, FM tone fields,
case-insensitive lookup, tokens without equals, empty body, and
extra whitespace.
@g4dpz
g4dpz force-pushed the optimise/flex-status-field-parsing branch from 95361ec to e74a5d7 Compare August 3, 2026 08:07
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.

2 participants