Slow build times with large numbers of [GenerateSerializer] DTOs
- Dominant language
- C#
- Stars
- 10.9k
- Forks
- 2.1k
- Avg merge
- 15h 1m
- Merged PRs (30d)
- 345
Description
While the source generator in Orleans is essential for runtime performance, the build process becomes significantly slow when a project contains a large number of DTOs marked with `[GenerateSerializer]`.
In our local development scenarios, the priority is rapid iteration and short rebuild times rather than optimized serialization performance. Currently, the source generator creates a substantial bottleneck in the inner development loop.
### **Reproduction**
I have created a [sample project](https://github.com/runerback/OrleansCodeGenBenchmark/) that benchmarks build times across different DTO counts to demonstrate this behavior.
**Benchmark Results:**
| DTOs Count | Metric | `[GenerateSerializer]` | Normal Build (No Orleans) | Custom JSON Wrapper |
| :--- | :--- | :--- | :--- | :--- |
| 100 | Build Duration (s) | 17.737 | 3.895 | 6.021 |
| 1000 | Build Duration (s) | 181.225 | 24.520 | 48.723 |
| **3000** | **Build Duration (s)** | **577.029** | **72.581** | **148.406** |
**System Info**
| OS | CPU | RAM | STORAGE |
| :--- | :--- | :--- | :--- |
| win11-x64 | i5-10600KF | 64GB | SSD |
### **Current Workaround & Pain Points**
To mitigate this, I implemented a workaround using a JSON-based approach. You can view the full implementation, including the [custom serializers and generators](https://github.com/runerback/OrleansCodeGenBenchmark/tree/main/src/Orleans.CodeGen.Benchmark.CustomGenerateSerializer/CustomSerializers) (of which the Codec is just one part), in the repository.
**Why this is hard to maintain:**
* **Attribute Swapping:** We have to wrap every DTO in `#if DEBUG` preprocessor directives to switch between official and custom attributes.
* **Tooling Overhead:** We had to write a custom Roslyn analyzer to handle `[Id]` checks and generation for the workaround.
* **IDE Noise:** The generated code (Copier/Activator/Codec) for the custom solution becomes visible in the IDE, cluttering the workspace compared to the "invisible" official source generator.
### **Requested Feature**
Provide a native mechanism—such as an MSBuild property or a property on the `GenerateSerializer` attribute—to opt-out of heavy source generation during local development.
The goal is to allow the build to use a more straightforward or dynamic serialization method when runtime performance is secondary to build speed, significantly improving the developer experience for large-scale projects.
Contributor guide
Assessment
This issue has not been assessed yet.