Skip to content

Generate GetDefaultMappings as an array instead of an iterator - #1737

Open
tmilnthorp wants to merge 2 commits into
angularsen:masterfrom
tmilnthorp:tmilntho/default-mappings-array
Open

tmilnthorp wants to merge 2 commits into
angularsen:masterfrom
tmilnthorp:tmilntho/default-mappings-array

Conversation

@tmilnthorp

Copy link
Copy Markdown
Collaborator

Each generated GetDefaultMappings() used yield return. The compiler turns each one into a hidden iterator class, so that's 129 extra classes in the DLL. This PR generates an array instead. The return type stays IEnumerable<UnitDefinition<TUnit>>, so there's no API change. The generated code reads the same apart from the array syntax.

QuantityInfo calls .Select(...).ToArray() on the mappings. Given an array, LINQ knows the count up front and allocates the result once.

The generator change and the regenerated code are separate commits.

master this PR
UnitsNet.dll (net10.0, Release) 1,885,696 B 1,691,648 B (−10.3%)
First ToString() (cold process) 355 ms 332 ms
Create all 129 QuantityInfos (cold process) 339 ms / 1,565 KB allocated 318 ms / 1,458 KB allocated

Hot-path benchmarks for ToString, Parse, conversions, arithmetic and QuantityInfoLookup lookups are unchanged within noise.

🤖 Generated with Claude Code

https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG

tmilnthorp and others added 2 commits October 6, 2026 11:21
Each yield-return method compiles to a hidden iterator class. Returning an
array removes 129 of those classes (-194 KB in the net10.0 DLL) and lets
QuantityInfo size its unit array up front. The return type is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG
@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98%. Comparing base (3bf1ef4) to head (6927559).

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1737     +/-   ##
========================================
- Coverage      98%     98%     -1%     
========================================
  Files         515     515             
  Lines       24092   22361   -1731     
========================================
- Hits        23692   21961   -1731     
  Misses        400     400             
Flag Coverage Δ
net48 97% <100%> (-1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

This branch has not been deployed

No deployments
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