Skip to content

Improve flash usage for embedded targets - #176

Merged
CramBL merged 2 commits into
AeroRust:mainfrom
Rimpampa:main
Nov 3, 2026
Merged

CramBL merged 2 commits into
AeroRust:mainfrom
Rimpampa:main

Conversation

@Rimpampa

Copy link
Copy Markdown
Contributor

With those simple changes I've managed to save almost 16KiB on my embedded project.

@CramBL

CramBL commented Oct 29, 2026

Copy link
Copy Markdown
Member

Hi, thanks for contributing. Can you explain your changes, what motivated exactly these changes, and any trade-offs to be aware of?

@Rimpampa

Rimpampa commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

The motivation comes from a need to decrease flash usage on the embedded project I'm working on. On my target is 16Kib / 256Kib ≈ 6% of the total space.

For the first commit the only practical change is in the error format: you lose the info of the new satellite which is extra/overflowing.

For the second commit, what occupies a lot of size is the std float parser, which I find to be too complex for this task. For example exponent notation is not allowed in NMEA.

The new parser still allows non standard syntax (e.g. +.05, 20.), if that is a problem I'll change it.

@Rimpampa Rimpampa closed this Oct 29, 2026
@Rimpampa Rimpampa reopened this Oct 29, 2026
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.04132% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.67%. Comparing base (2fa4e56) to head (a447338).

Files with missing lines Patch % Lines
src/parser.rs 57.14% 3 Missing ⚠️
src/sentences/gbs.rs 50.00% 2 Missing ⚠️
src/sentences/gsv.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #176      +/-   ##
==========================================
- Coverage   82.86%   82.67%   -0.19%     
==========================================
  Files          39       40       +1     
  Lines        1634     1680      +46     
==========================================
+ Hits         1354     1389      +35     
- Misses        280      291      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@CramBL

CramBL commented Oct 29, 2026

Copy link
Copy Markdown
Member

The motivation comes from a need to decrease flash usage on the embedded project I'm working on. On my target is 16Kib / 256Kib ≈ 6% of the total space.

For the first commit the only practical change is in the error format: you lose the info of the new satellite which is extra/overflowing.

For the second commit, what occupies a lot of size is the std float parser, which I find to be too complex for this task. For example exponent notation is not allowed in NMEA.

The new parser still allows non standard syntax (e.g. +.05, 20.), if that is a problem I'll change it.

Sounds like a great change then.

I have a few issues that we should resolve before merging:

  1. float/double is a C/C++ concept, so let's not call an f64 a "double" in Rust, it's a terrible name 😄 just float32 and float64 would be fine.
  2. Replacing a floating point parser should be done with care, so adding a differential fuzz test would be appropriate (use proptest)
  3. (optional) Perhaps we should optimize a bit

@CramBL CramBL left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better 😄 just a small thing still

Comment thread src/sentences/float.rs Outdated

/// Parse a plain decimal number into an `f64`, returning the number and the
/// number of input bytes consumed.
pub(crate) fn parse_f64_inner(input: &str) -> Result<(f64, usize), &'static str> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only parse32 and parse64 that are actually used outside this module right? So can you leave them as the only functions with a pub qualifier?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure 👍

@Rimpampa

Copy link
Copy Markdown
Contributor Author

Ok so now its cleaner with a separate module and more trustworthy with the added tests.

The naming was initially taken from the nom crate, but I agree it doesn't make sense to talk about float/double in rust (not sure why the keep it like that).

Parser is not "correct" i a strict way, the rounding is off by a tiny amount measured to be a maximum of 4 ULP for 64 bit floats and 1 ULP for 32 bits, which seems to me acceptable given that the error is well below the precision of the actual measurement.

Let me know if there is anything else to change

@CramBL

CramBL commented Oct 29, 2026

Copy link
Copy Markdown
Member

Ok so now its cleaner with a separate module and more trustworthy with the added tests.

The naming was initially taken from the nom crate, but I agree it doesn't make sense to talk about float/double in rust (not sure why the keep it like that).

Parser is not "correct" i a strict way, the rounding is off by a tiny amount measured to be a maximum of 4 ULP for 64 bit floats and 1 ULP for 32 bits, which seems to me acceptable given that the error is well below the precision of the actual measurement.

Let me know if there is anything else to change

Yes I noticed precision loss as well, but even though some receivers can output coordinates with 6 decimal precision, it is still not enough for 4 ULP to matter. 4 ULP would be less than a micron.

I would still request a modification to the float module:

Can you have the 2 functions used outside the module as pub(crate) at the top of the file and the rest of the function should have no pub-qualifier

@Rimpampa

Copy link
Copy Markdown
Contributor Author

I can move them at the top, but only parse_f64_inner is not being used outside of the module, or did I get what you asked wrong? 😅

@CramBL

CramBL commented Oct 29, 2026

Copy link
Copy Markdown
Member

I can move them at the top, but only parse_f64_inner is not being used outside of the module, or did I get what you asked wrong? 😅

Ah, yes, sorry, too many parse/float in this PR I misread it 😄

@CramBL

CramBL commented Oct 29, 2026

Copy link
Copy Markdown
Member

Thanks!

@CramBL
CramBL self-requested a review October 29, 2026 22:29

@CramBL CramBL left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait I was too quick to approve. Can you fold the refactor commit into the feature commit so we don't have both the feature and the refactor of the same feature in the commit history on main?

This commit adds a new module for decimal parsing, alongside a fuzzing testsuite (using proptest).
@Rimpampa

Rimpampa commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@CramBL poke 👀 (did I miss any request?)

@CramBL

CramBL commented Nov 3, 2026

Copy link
Copy Markdown
Member

@CramBL poke 👀 (did I miss any request?)

No. I didn't get any notification to re-review. If you had clicked the "re-request review" button I would've looked at it 😄

@CramBL
CramBL merged commit a8369a1 into AeroRust:main Nov 3, 2026
15 checks passed
@CramBL

CramBL commented Nov 3, 2026

Copy link
Copy Markdown
Member

Thanks!

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