# Accelerating Dart code generation

Source: https://www.youtube.com/watch?v=6PKIv7yUKwQ
Recap page: https://rapidrecap.app/video/6PKIv7yUKwQ
Generated: 2025-12-17T21:35:12.665+00:00

---
## Quick Overview

Dart code generation build times are significantly accelerated by implementing Dart 3.18's new language feature, Augmentations, which allows code generators like json_serializable to reduce boilerplate by adding necessary functions directly to the original class part file, resulting in performance improvements up to 3.8x faster for incremental builds across various packages like built_value, freezed, and go_router_builder.

**Key Points:**
- Augmentations, a new Dart language feature, allow code generators to significantly reduce boilerplate by injecting code (like JSON serialization/deserialization methods) directly into the original class's part file.
- Performance benchmarks show substantial speedups: json_serializable saw incremental build times improve by 3.8x faster using the new method compared to older build_runner versions.
- Specific package performance improvements include built_value being 3.6x faster, freezed being 3.8x faster, and go_router_builder being 2.4x faster.
- The overhead of code generation is drastically reduced; for a project with 3,000 generated libraries, code generation runs twice as fast, and the build time graph shows a flatter curve for the newer build_runner versions.
- Augmentations support parts with imports and primary constructors, further streamlining how generated code interacts with the original source code.
- The speaker demonstrated using `dart run build_runner build --delete-conflicting-outputs` and noted that the console output looks cleaner with the new approach.

![Screenshot at 00:05: The title slide introduces the topic "Flutter Flight Plans: Chart your course for the future of app development," setting the stage for discussing planned improvements in Dart development tooling.](https://ss.rapidrecap.app/screens/6PKIv7yUKwQ/00-00-05.png)

**Context:** This video, presented by John Ryan from the Flutter team as part of 'Flutter Flight Plans,' focuses on major performance improvements coming to Dart code generation tools, particularly those relying on the build_runner ecosystem. The core topic revolves around how upcoming language features in Dart, specifically Augmentations, will help reduce the boilerplate code generated for tasks like JSON serialization and data class creation, thereby speeding up the development cycle.

## Detailed Analysis

The video details how upcoming Dart language features, specifically Augmentations, will dramatically speed up code generation processes, primarily benefiting packages like json_serializable, built_value, freezed, and go_router_builder. The presenter shows that with the old method, generating JSON serialization/deserialization functions required writing boilerplate code in a separate part file (`potion.g.dart`). With Augmentations, code generators can use the `augment class Potion` keyword to inject necessary methods directly into the original class's part file, bypassing the need for manual boilerplate or complex generated files for certain functions. This dramatically reduces the amount of code processed during compilation. Performance testing demonstrated this improvement: for a project with 100 libraries, the build time dropped from 105 seconds to 12 seconds on an M1 Mac when using the optimized code generation, confirming user reports of significant speed gains (up to 3.8x faster incremental builds). The presenter also highlights other upcoming features that support this trend: Parts with imports and Primary constructors, which simplify class definitions and boilerplate reduction further. The conclusion encourages developers to upgrade their `build_runner` package to benefit from these optimizations.

### Introduction to Code Generation Pain Points

- Boilerplate code for JSON serialization and data classes is inconvenient
- Previous methods required manual boilerplate or generated code in separate part files
- Build times suffer in large projects.

### Build Runner Performance Benchmarks

- Incremental build time vs. #libraries shows significant quadratic growth for older versions (2.4.15 and 2.10.2) but near-linear time for the optimized version (2.10.3).
- For 3,000 libraries, the oldest version takes nearly 700 seconds, while the newest is near zero.

### Future Features

- Augmentations coming soon to reduce boilerplate by injecting code directly into the original class part file
- Parts with imports and Primary constructors also aim to simplify code structure and reduce build overhead.

### Package-Specific Improvements

- built_value is 3.6x faster
- freezed is 3.8x faster
- go_router_builder is 2.4x faster.
- User testimony confirms a drop from 105s to 12s on an M1 Mac for clean builds.

### Conclusion and Next Steps

- The Dart team continues to invest in making code generation faster and more robust without breaking existing workflows.
- Users should run `dart pub upgrade build_runner` to get the latest version.

![Screenshot at 00:02: Visual representation of code generation elements floating, including a smartphone outline and database icons, symbolizing the context of software development tools.](https://ss.rapidrecap.app/screens/6PKIv7yUKwQ/00-00-02.png)
![Screenshot at 00:29: A screenshot of the pub.dev page for the build\_runner package, listing common builders like auto\_route\_generator and build\_value\_generator.](https://ss.rapidrecap.app/screens/6PKIv7yUKwQ/00-00-29.png)
![Screenshot at 00:35: Code example showing a manual Dart class definition for a 'Potion' requiring explicit boilerplate for the constructor and JSON mapping functions.](https://ss.rapidrecap.app/screens/6PKIv7yUKwQ/00-00-35.png)
![Screenshot at 01:26: A bar chart displaying commits over the last year for the dart-lang/build repository, showing development activity.](https://ss.rapidrecap.app/screens/6PKIv7yUKwQ/00-01-26.png)
![Screenshot at 01:32: A line graph comparing incremental build times \(seconds\) versus the number of libraries, clearly illustrating the quadratic slowdown of older build\_runner versions versus the near-zero impact of the optimized version.](https://ss.rapidrecap.app/screens/6PKIv7yUKwQ/00-01-32.png)
