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

Slow build and uses 16GB of RAM with a large file and nullable enabled #76568

Open
meziantou opened this issue Dec 26, 2024 · 2 comments
Open
Assignees
Milestone

Comments

@meziantou
Copy link
Contributor

meziantou commented Dec 26, 2024

Version Used: '4.12.0-3.24570.6 (913fb4e)'. Language version: 13.0.

Steps to Reproduce:

The repro has one large generated file (~160k lines) with #nullable enable at the top. Most lines add an entry in a ConcurrentDictionary.

  1. git clone https://github.com/meziantou/repro-roslyn-nullable-largefile
  2. dotnet build

The problematic file is https://github.com/meziantou/repro-roslyn-nullable-largefile/blob/main/HstsDomainPolicyCollection.g.cs

Expected Behavior:
The application builds without using more than 16GB of RAM

Actual Behavior:

Notes:
Disabling nullables in the generated files seems to fix the issue. It builds on Linux and it's faster on Windows. Note that there is a significant difference between Windows (80s) and Linux (20s), but maybe it's related to GitHub runners.

I wonder if there is something in Roslyn that could be improved or if I should update the code generator to use another pattern.

Note: This code was just a first experiment to create my project. My final code doesn't use this logic as it has multiple drawbacks (IDE is not usage, JIT takes too much time).

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 26, 2024
@Youssef1313
Copy link
Member

A quick hack you could try is to split all these TryAdd calls into multiple methods and see if it improves performance. I'm not confident it will work, but I think it's worth trying.

@meziantou
Copy link
Contributor Author

meziantou commented Dec 27, 2024

I made a quick test to split the 160k statements in multiple methods:

  • 1 method: 40s
  • 2 methods: 27s
  • 4 methods: 17s
  • 8 methods: 12s
  • 16 methods: 10s
  • 32 methods: 10s

I tested it on a machine with 10 cores. When using 32 methods, the RAM usage is also much lower than with 1 method (2GB vs 10GB).

@jaredpar jaredpar added Feature - Nullable Reference Types Nullable Reference Types and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 6, 2025
@jaredpar jaredpar added this to the 17.14 milestone Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants