Skip to content

Conversation

edwardneal
Copy link
Contributor

@edwardneal edwardneal commented May 20, 2025

Description

This PR's diff is much smaller than it looks! There's an embedded XML resource, and adjusting this meant that the indentation levels changed. When that's accounted for, the PR becomes much smaller - around 300 lines, rather than 7800.

This PR relates to #1942 and #1261. At present, there are two identical copies of the Microsoft.Data.SqlClient.SqlMetaData.xml embedded resource in the netfx and the netcore projects. This PR merges these with a single file. More importantly though, this embedded resource is used only within DbMetaDataFactory; it's deserialized using DataSet.ReadXml, where it is eventually used in SqlConnection.GetSchema.

DataSet.ReadXml isn't trim-safe - it uses XML serialization in the background. I've replaced this with a simple parsing routine which runs against the embedded resource and adds the rows manually.

The net result is smaller, faster and more efficient. Sizoscope confirms that this PR cuts the file size of a simple application by 3.8MB, from 20.4MB to 16.6MB. Benchmark results for this in isolation are:

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Before 1,819.7 μs 25.07 μs 23.45 μs 1.00 0.02 187.5000 39.0625 829.81 KB 1.00
After 738.9 μs 3.25 μs 2.71 μs 0.41 0.01 62.5000 19.5313 307.74 KB 0.37

Separately, I noticed that my earlier PR #3309 generated two warnings when publishing because it wasn't using a fully-qualified type name. I've adjusted this.

Issues

Relates to #1942.
Relates to #1261.
Follows up #3309.

Testing

All tests continue to pass.

There's a lot of validation of the structure of the XML in the embedded resource, and this is done with debug assertions. I've treated this as hardcoded at the point of build, so haven't used exceptions for this. I can change this if needed.

This removes a reference to the built-in XML deserialization, which is slower and isn't trim-safe
@edwardneal edwardneal requested a review from a team as a code owner May 20, 2025 23:08
Copy link
Contributor

@mdaigle mdaigle left a comment

Choose a reason for hiding this comment

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

A few questions to help with my understanding

Copy link
Contributor

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

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

Asking for some clarification on why we're reading this XML at runtime.

@paulmedynski
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link

codecov bot commented May 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.22%. Comparing base (832e8da) to head (21cad07).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3369      +/-   ##
==========================================
- Coverage   65.12%   62.22%   -2.90%     
==========================================
  Files         300      294       -6     
  Lines       65379    65183     -196     
==========================================
- Hits        42578    40563    -2015     
- Misses      22801    24620    +1819     
Flag Coverage Δ
addons ?
netcore 66.64% <100.00%> (-1.70%) ⬇️
netfx 60.84% <100.00%> (-5.54%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@mdaigle mdaigle added this to the 6.1-preview2 milestone May 23, 2025
@mdaigle mdaigle merged commit a1bfea8 into dotnet:main May 23, 2025
237 checks passed
@edwardneal edwardneal deleted the feat/aot-2 branch May 23, 2025 16:36
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.

3 participants