Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing deterministic build bug with dotnet.exe #4953

Merged
merged 2 commits into from
Jul 29, 2021
Merged

Conversation

guimafelipe
Copy link
Member

Fixes Issue #3876

Main PR

Description

Building a WPF .NET Core project with dotnet.exe is not deterministic, but building it with msbuild.exe is deterministic as expected.

This PR is based on this fix from @MichaeIDietrich.

Customer Impact

This issue may break incremental builds.

Regression

No regression.

Testing

The fix was testing building some projects using the dotnet build command, and comparing the generated files using a diff program. Without the fix, the files are almost always different.

Risk

@guimafelipe guimafelipe requested a review from a team as a code owner July 29, 2021 14:06
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Jul 29, 2021
@ghost ghost requested review from fabiant3, ryalanms and SamBent July 29, 2021 14:06
@guimafelipe guimafelipe removed the request for review from SamBent July 29, 2021 14:07
@ryalanms
Copy link
Member

LGTM. I've included @MichaeIDietrich's commit as well so it's tracked in GitHub.

@ryalanms
Copy link
Member

This will need to be backported to 5.0 and 3.1.

@ryalanms ryalanms merged commit e53b1ec into main Jul 29, 2021
guimafelipe added a commit that referenced this pull request Jul 29, 2021
* adding orderby in foreach loop

* Order references to make BAML deterministic

Co-authored-by: Felipe da Conceicao Guimaraes <felipeda@microsoft.com>
Co-authored-by: Michael Dietrich <dev.michaeldietrich@outlook.de>
@ThomasGoulet73
Copy link
Contributor

Is this code on a hot path ? Because it is considerably slower than the original code (Approx. 30 times slower). One easy way to make it faster would be to use Ordinal comparison (It's currently using CurrentCulture comparison as the default of OrderBy). If I understand the fix correctly, the string comparison doesn't really matter, we only need to make sure to always have the same order of items.

We would only need to replace .OrderBy(s => s) with .OrderBy(s => s, StringComparer.Ordinal)

Here's the result with a 100 items:

Method assemblyPathTable Mean Error StdDev Ratio RatioSD Code Size Gen 0 Gen 1 Gen 2 Allocated
Old Syste(...)onary [47] 1.071 us 0.0083 us 0.0069 us 1.00 0.00 370 B 0.0076 - - 56 B
Linq Syste(...)onary [47] 35.873 us 0.7050 us 1.1584 us 33.50 1.25 755 B 0.5493 - - 3,792 B
LinqOrdinal Syste(...)onary [47] 10.102 us 0.1886 us 0.1937 us 9.47 0.20 776 B 0.5951 - - 3,760 B

ryalanms pushed a commit that referenced this pull request Aug 9, 2021
* Fixing deterministic build bug with dotnet.exe (#4953)

* adding orderby in foreach loop

* Order references to make BAML deterministic

Co-authored-by: Felipe da Conceicao Guimaraes <felipeda@microsoft.com>
Co-authored-by: Michael Dietrich <dev.michaeldietrich@outlook.de>

* adding optimization

Co-authored-by: Felipe da Conceicao Guimaraes <felipeda@microsoft.com>
Co-authored-by: Michael Dietrich <dev.michaeldietrich@outlook.de>
@ghost ghost locked as resolved and limited conversation to collaborators Apr 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants