Skip to content

Only generate the polyfills used by the code - #1526

Merged
meziantou merged 1 commit into
mainfrom
feature/polyfill-config-assembly-size-78017d
Sep 15, 2026
Merged

meziantou merged 1 commit into
mainfrom
feature/polyfill-config-assembly-size-78017d

Conversation

@meziantou

Copy link
Copy Markdown
Owner

What

MeziantouPolyfill_IncludedPolyfills was set to *, which Meziantou.Polyfill does not treat as a filter (IncludedMembers: <null> in Debug.g.cs), so ~800 polyfills (3.6 MB of generated source) were compiled into every assembly. It is now an explicit list of the 36 polyfills the code uses.

Assembly size (Release, netstandard2.0, packed in the NuGet package)

Roslyn Meziantou.Analyzer Meziantou.Analyzer.CodeFixers
4.8 2,778,112 → 1,860,608 2,356,736 → 859,648
4.14 2,780,160 → 1,862,144 2,357,248 → 860,160
5.0 2,780,160 → 1,862,144 2,357,248 → 860,160
5.6 2,780,672 → 1,862,656 2,358,272 → 861,184
5.9 2,787,328 → 1,869,312 2,358,272 → 861,184

Total for the 10 packed DLLs: 25.7 MB → 13.6 MB (-47%). The net10.0 builds are also ~90 KB smaller each.

Verification

  • Beyond compiling, I checked that no call silently binds to a different overload (e.g. ReadOnlySpan<char>.Contains falling back to Enumerable.Contains). I disassembled the Meziantou.* types before and after, for every Roslyn version on netstandard2.0 and for net10.0 on Roslyn 5.9, and the IL is identical. The only difference is a [CompilerFeatureRequired("RefStructs")] marker no longer emitted on two ref structs, which only matters to pre-C# 7.2 compilers referencing the assembly.
  • dotnet build of the whole solution: 0 errors, 0 warnings.
  • Tests: Roslyn 5.9 (4,720 passed) and Roslyn 4.8 (4,599 passed). The other versions were built but their tests were not run locally.

Notes for reviewers

  • New code using a polyfill that is not in the list will fail to compile on netstandard2.0; add its XML doc ID to the list. Set MeziantouPolyfill_GenerateDebugFile=true to list the available IDs in Debug.g.cs.
  • Some polyfills use other polyfills without declaring them as dependencies, so they are listed explicitly (worth fixing in Meziantou.Polyfill):
    • T:System.Index / T:System.RangeDoesNotReturnAttribute
    • T:System.Runtime.CompilerServices.DefaultInterpolatedStringHandlerString.TryCopyTo(Span<char>), String.CopyTo(Span<char>)

MeziantouPolyfill_IncludedPolyfills was set to '*', which is not a filter,
so ~800 polyfills were generated. Listing only the polyfills used by the
code reduces the size of the netstandard2.0 assemblies by about 47%.
@meziantou
meziantou merged commit 5b85a24 into main Sep 15, 2026
13 checks passed
@meziantou
meziantou deleted the feature/polyfill-config-assembly-size-78017d branch September 15, 2026 13:46
This was referenced Sep 15, 2026
IhateTrains pushed a commit to ParadoxGameConverters/ImperatorToCK3 that referenced this pull request Sep 16, 2026
Updated
[Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer)
from 3.0.235 to 3.0.259.

<details>
<summary>Release notes</summary>

_Sourced from [Meziantou.Analyzer's
releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._

## 3.0.259

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.259>

## What's Changed
* Only generate the polyfills used by the code by @​meziantou in
meziantou/Meziantou.Analyzer#1526


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.258...3.0.259

## 3.0.258

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.258>

## What's Changed
* chore(deps): update dependency meziantou.framework.roslyn to 1.2.0 by
@​renovate[bot] in
meziantou/Meziantou.Analyzer#1525


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.257...3.0.258

## 3.0.257

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.257>

## What's Changed
* Use GetTypeByMetadataName unless the type is commonly declared as
internal in several assemblies by @​meziantou in
meziantou/Meziantou.Analyzer#1523


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.256...3.0.257

## 3.0.256

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.256>

## What's Changed
* Fix metadata names that could never resolve in MA0003, MA0001 and
MA0060 by @​meziantou in
meziantou/Meziantou.Analyzer#1522


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.255...3.0.256

## 3.0.255

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.255>

## What's Changed
* Add an option to include extension methods from namespaces that are
not imported in the rules using OverloadFinder by @​meziantou in
meziantou/Meziantou.Analyzer#1521


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.254...3.0.255

## 3.0.254

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.254>

## What's Changed
* Remove the unreachable string.Join branch of MA0089 by @​meziantou in
meziantou/Meziantou.Analyzer#1504
* Fix MA0018 reporting one diagnostic per event accessor by @​meziantou
in meziantou/Meziantou.Analyzer#1505
* chore(deps): update all dependencies to 1.0.172 by @​renovate[bot] in
meziantou/Meziantou.Analyzer#1507
* Report MA0070 on every declaration that can be obsolete by @​meziantou
in meziantou/Meziantou.Analyzer#1508
* Remove the discarded message argument of MA0080 by @​meziantou in
meziantou/Meziantou.Analyzer#1509
* Report MA0068 on the parameter and property placements of
NotNullIfNotNull by @​meziantou in
meziantou/Meziantou.Analyzer#1510
* Include the preprocessor trivia in the MA0202 branch comparison by
@​meziantou in meziantou/Meziantou.Analyzer#1511
* Report MA0179 when the constant is on the left of the length
comparison by @​meziantou in
meziantou/Meziantou.Analyzer#1512
* Fix the MA0166 message saying "available tokens" by @​meziantou in
meziantou/Meziantou.Analyzer#1513
* Detect the ConfigureAwait of the async enumerable in the MA0004
foreach analysis by @​meziantou in
meziantou/Meziantou.Analyzer#1506
* Report MA0206 on record struct and interface declarations by
@​meziantou in meziantou/Meziantou.Analyzer#1514
* Report MA0147 on async void method groups by @​meziantou in
meziantou/Meziantou.Analyzer#1515
* Report MA0051 on expression bodies of properties, indexers, and
operators by @​meziantou in
meziantou/Meziantou.Analyzer#1517
* Clarify the MA0095 comment about the Equals(object) lookup by
@​meziantou in meziantou/Meziantou.Analyzer#1518
* Report relational and generic math NaN comparisons in MA0082 by
@​meziantou in meziantou/Meziantou.Analyzer#1519
* Cache the MA0042 "no async equivalent" results per call-site scope by
@​meziantou in meziantou/Meziantou.Analyzer#1520
* Report the contextual keywords in MA0154 by @​meziantou in
meziantou/Meziantou.Analyzer#1516


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.253...3.0.254

## 3.0.253

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.253>

## What's Changed
* Share the argument list logic of the code fixes that add an argument
by @​meziantou in
meziantou/Meziantou.Analyzer#1503


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.252...3.0.253

## 3.0.252

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.252>

## What's Changed
* Preserve the variable scope in the MA0004 code fix by @​meziantou in
meziantou/Meziantou.Analyzer#1502


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.251...3.0.252

## 3.0.251

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.251>

## What's Changed
* Keep the initialization order in the MA0004 code fix by @​meziantou in
meziantou/Meziantou.Analyzer#1496
* Do not offer the MA0082 code fix when both operands are NaN by
@​meziantou in meziantou/Meziantou.Analyzer#1497
* Report MA0224/MA0225 when an earlier assignment configures another
instance by @​meziantou in
meziantou/Meziantou.Analyzer#1498
* Fix MA0040 inserting the CancellationToken in an invalid argument
position by @​meziantou in
meziantou/Meziantou.Analyzer#1499
* Preserve argument binding in the MA0074 code fix by @​meziantou in
meziantou/Meziantou.Analyzer#1500
* Fix MA0011 inserting the IFormatProvider in an invalid argument
position by @​meziantou in
meziantou/Meziantou.Analyzer#1501


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.250...3.0.251

## 3.0.250

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.250>

## What's Changed
* Report MA0163 when an assignment cannot fix the configuration used by
Process.Start by @​meziantou in
meziantou/Meziantou.Analyzer#1489
* Fix MA0166 inserting the TimeProvider in an invalid argument position
by @​meziantou in
meziantou/Meziantou.Analyzer#1490
* Do not report MA0214 when the function cannot be made async by
@​meziantou in meziantou/Meziantou.Analyzer#1491
* Preserve argument binding in the MA0108 code fix by @​meziantou in
meziantou/Meziantou.Analyzer#1492
* Add the type to the parameter added by the MA0106 code fix on a typed
lambda by @​meziantou in
meziantou/Meziantou.Analyzer#1495


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.249...3.0.250

## 3.0.249

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.249>

## What's Changed
* MA0177: preserve nested XML elements such as <see/> when collapsing by
@​meziantou in meziantou/Meziantou.Analyzer#1481
* Fix MA0184 code fix keeping doubled braces as literal text by
@​meziantou in meziantou/Meziantou.Analyzer#1465
* Do not report MA0209/MA0210 for arguments that cannot be passed by
reference by @​meziantou in
meziantou/Meziantou.Analyzer#1469
* Do not report MA0148/MA0149 when the constant does not convert to the
operand type by @​meziantou in
meziantou/Meziantou.Analyzer#1470
* Do not report MA0028 for string.Join overloads without an AppendJoin
equivalent by @​meziantou in
meziantou/Meziantou.Analyzer#1475
* chore(deps): update all dependencies by @​renovate[bot] in
meziantou/Meziantou.Analyzer#1477
* Fix MA0193 code fix producing invalid calls with named arguments by
@​meziantou in meziantou/Meziantou.Analyzer#1486
* Do not report MA0173 when the value cannot be captured by a lambda by
@​meziantou in meziantou/Meziantou.Analyzer#1487
* Do not report MA0106 when the factory writes the captured variable by
@​meziantou in meziantou/Meziantou.Analyzer#1488


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.248...3.0.249

## 3.0.248

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.248>

## What's Changed
* Do not report MA0065 when the invoked equality member is overridden by
@​meziantou in meziantou/Meziantou.Analyzer#1485
* Do not report MA0152 when the inner await suppresses the exceptions by
@​meziantou in meziantou/Meziantou.Analyzer#1484


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.247...3.0.248

## 3.0.247

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.247>

## What's Changed
* Do not report MA0215 when ConfigureAwait changes what the method does
by @​meziantou in
meziantou/Meziantou.Analyzer#1483


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.246...3.0.247

## 3.0.246

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.246>

## What's Changed
* Fix MA0158 code fix when the field is assigned in another document by
@​meziantou in meziantou/Meziantou.Analyzer#1478
* Do not report MA0173 when the return value of CompareExchange is used
by @​meziantou in
meziantou/Meziantou.Analyzer#1479
* Do not report MA0066 on ImmutableSortedDictionary by @​meziantou in
meziantou/Meziantou.Analyzer#1480


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.245...3.0.246

## 3.0.245

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.245>

## What's Changed
* Do not report MA0158 when the value cannot be migrated to
System.Threading.Lock by @​meziantou in
meziantou/Meziantou.Analyzer#1476


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.244...3.0.245

## 3.0.244

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.244>

## What's Changed
* Fix MA0028 changing escaped braces when replacing AppendFormat with
Append by @​meziantou in
meziantou/Meziantou.Analyzer#1474


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.243...3.0.244

## 3.0.243

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.243>

## What's Changed
* Do not report MA0078 when the selector does more than casting its
element by @​meziantou in
meziantou/Meziantou.Analyzer#1473


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.242...3.0.243

## 3.0.242

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.242>

## What's Changed
* Do not report MA0111 in expression trees by @​meziantou in
meziantou/Meziantou.Analyzer#1471
* Do not offer the MA0098 Last() code fix when the source cannot be
evaluated twice by @​meziantou in
meziantou/Meziantou.Analyzer#1472


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.241...3.0.242

## 3.0.241

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.241>

## What's Changed
* Do not merge MA0148/MA0149 comparisons when the operand can change
between evaluations by @​meziantou in
meziantou/Meziantou.Analyzer#1466
* Fix MA0210 checking the wrong parameter for reordered named arguments
by @​meziantou in
meziantou/Meziantou.Analyzer#1467
* Do not report MA0184 when the interpolated string is converted to
IFormattable by @​meziantou in
meziantou/Meziantou.Analyzer#1468


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.240...3.0.241

## 3.0.240

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.240>

## What's Changed
* Remove every dollar of raw strings in MA0184 code fix by @​meziantou
in meziantou/Meziantou.Analyzer#1464


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.239...3.0.240

## 3.0.239

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.239>

## What's Changed
* Do not report MA0005 for arrays of pointers by @​meziantou in
meziantou/Meziantou.Analyzer#1460
* Fix MA0171 code fix omitting parentheses around the generated pattern
by @​meziantou in
meziantou/Meziantou.Analyzer#1461
* Do not offer the MA0044 code fix when removing ToString would drop
argument side effects by @​meziantou in
meziantou/Meziantou.Analyzer#1462
* Import System.Threading.Tasks in MA0152 code fix by @​meziantou in
meziantou/Meziantou.Analyzer#1463


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.238...3.0.239

## 3.0.238

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.238>

## What's Changed
* Preserve interpolation alignment in MA0052 code fix by @​meziantou in
meziantou/Meziantou.Analyzer#1454
* Do not report MA0160 when ContainsKey is explicitly implemented by
@​meziantou in meziantou/Meziantou.Analyzer#1453


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.237...3.0.238

## 3.0.237

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.237>

## What's Changed
* Fix MA0127 code fix producing uncompilable code for object and span
operands by @​meziantou in
meziantou/Meziantou.Analyzer#1459
* MA0113: Only report DateTime constructors with the Utc kind by
@​meziantou in meziantou/Meziantou.Analyzer#1458
* Preserve attribute inheritance behavior in the MA0179 code fix by
@​meziantou in meziantou/Meziantou.Analyzer#1457
* MA0239: Do not report GetType() on a property by @​meziantou in
meziantou/Meziantou.Analyzer#1456
* MA0052: Suggest the first declared member when the enum value has
aliases by @​meziantou in
meziantou/Meziantou.Analyzer#1455
* Fix MA0089 treating an integer start index or count as
StringComparison.Ordinal by @​meziantou in
meziantou/Meziantou.Analyzer#1452
* chore(deps): update all dependencies by @​renovate[bot] in
meziantou/Meziantou.Analyzer#1445


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.236...3.0.237

## 3.0.236

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.236>

## What's Changed
* Exclude CsWinRT-required partial types from MA0204 by @​meziantou with
@​Copilot in meziantou/Meziantou.Analyzer#1451


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.235...3.0.236

Commits viewable in [compare
view](meziantou/Meziantou.Analyzer@3.0.235...3.0.259).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Meziantou.Analyzer&package-manager=nuget&previous-version=3.0.235&new-version=3.0.259)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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