Skip to content

[Repo Assist] Add trimming support to runtime Core libraries (closes #1436)#1685

Merged
dsyme merged 2 commits intomainfrom
repo-assist/fix-issue-1436-trimming-support-5279a481c4ea2b3f
Mar 1, 2026
Merged

[Repo Assist] Add trimming support to runtime Core libraries (closes #1436)#1685
dsyme merged 2 commits intomainfrom
repo-assist/fix-issue-1436-trimming-support-5279a481c4ea2b3f

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 1, 2026

🤖 This is an automated PR from Repo Assist.

Implements trimming support for all FSharp.Data runtime assemblies, allowing Blazor WASM and other trimmed deployments to reduce bundle size significantly.

Closes #1436


What changed

IsTrimmable=true added to all runtime Core libraries

The following NuGet packages now declare themselves as trimmable, allowing the .NET trimmer/linker to remove unused code when publishing trimmed applications (e.g. Blazor WASM):

  • FSharp.Data.Http
  • FSharp.Data.Runtime.Utilities
  • FSharp.Data.Json.Core
  • FSharp.Data.Csv.Core
  • FSharp.Data.Xml.Core
  • FSharp.Data.Html.Core
  • FSharp.Data.WorldBank.Core

The design-time assembly (FSharp.Data.DesignTime) and the type provider host (FSharp.Data) are intentionally excluded — they only run in the compiler/IDE, not in end-user apps.

Reflection removed from Http.fs

Two reflection call sites were blocking safe trimming:

  1. runningOnMono — this let binding used System.Type.GetType "Mono.Runtime" to detect the Mono runtime, but was never actually used anywhere. It has been removed entirely.

  2. reraisePreserveStackTrace — previously used typeof(exn).GetField("_remoteStackTraceString", BindingFlags.Instance ||| BindingFlags.NonPublic) to preserve exception stack traces via a private field hack. Replaced with the standard ExceptionDispatchInfo.Capture(e).Throw() API (available since netstandard1.1), which is both trim-safe and semantically superior.

The open System.Reflection import is also removed as it is no longer needed.

Rationale

IsTrimmable=true signals to the .NET trimmer that a library has no unsafe reflection usage and can have unreachable code stripped. Without this flag, the trimmer must preserve the entire assembly to be safe, resulting in significantly larger bundles.

The StructuralTypes.fs/StructuralInference.fs use of typeof(T) is trim-safe — these are compile-time constants, not dynamic lookups.

Test Status

✅ Build succeeded (0 errors, pre-existing warnings only)
✅ Format check passed (fantomas)
✅ All 800 tests passed across FSharp.Data.Core.Tests, FSharp.Data.DesignTime.Tests, FSharp.Data.Tests, and FSharp.Data.Reference.Tests

Generated by Repo Assist for issue #1436

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@da02dddebe71d9a937665abdcd1f5214dab852a7

… Http.fs

- Mark FSharp.Data.Http, FSharp.Data.Runtime.Utilities, FSharp.Data.Json.Core,
  FSharp.Data.Csv.Core, FSharp.Data.Xml.Core, FSharp.Data.Html.Core, and
  FSharp.Data.WorldBank.Core as IsTrimmable=true
- Replace reflection-based reraisePreserveStackTrace in Http.fs with
  ExceptionDispatchInfo.Capture(e).Throw() (cleaner and trim-safe)
- Remove dead runningOnMono code that used System.Type.GetType reflection
- Remove now-unneeded open System.Reflection import

Closes #1436

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review March 1, 2026 13:38
@dsyme dsyme merged commit 32c2ce2 into main Mar 1, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-1436-trimming-support-5279a481c4ea2b3f branch March 1, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is it possible to make this library trimmable by default

1 participant