Optimizations

The generator replaces what Spring does at run time with reflection: finding beans, creating them, reading their properties, proxying them for AOP. It writes plain Dart code for all of it at build time. This section explains the choices that keep that code small and the build fast.

Why

Generated code is code the app ships. A naive generator would describe every class completely, write a proxy class for every bean and put every starter module into every app. That works, but the app carries a lot of code that never runs, and on Flutter and the web that means a bigger download and a slower start.

The build sees the whole application: its beans, its aspects, its calls, its configuration. So it can leave out what the application provably does not use, and say so clearly when something it did not see turns up at run time.

Overview

Optimization What it saves Page
No reflection dart:mirrors is not used; everything is plain constructor calls and closures, which work in AOT, Flutter and on the web and survive minification How the generation works
Code the compiler can tree-shake Generated references are direct (create: (r) => Greeter(r.dependency<Clock>(name: r'clock'))), descriptions are constants with top-level functions, conditional code is behind compile-time constants, so the Dart compiler removes what nothing reaches this page, below
Only what runs: introspection A class is described only for what the application does with it: getters, constructor and setters, or methods Only what runs: introspection
AOP proxy pruning No proxy class for a bean that no advice can match, and only the advised members in the proxies that stay AOP proxies
Deferred proxies Starters write no proxy classes for their beans; the application writes only those its aspects need AOP proxies
Modules left out of the build A property of the application keeps a starter module (a debug panel) out of the app, or out of a release only Modules left out of the build
Starter parts The generator is a core plus one part per starter, and a part runs only when the application reaches its starter; a part can follow a build key like a module How the generation works, Parts of the generator by key
Build speed Files are checked by text before they are resolved, only the needed bodies are resolved, extra work runs only when it can remove something Build speed

Code the compiler can remove

Dart's compilers for release builds (dart2js, AOT) remove code nothing references: tree shaking. Reflection defeats it, because any class might be looked up by name. Generated code helps it:

What stays the same

Every optimization keeps the behaviour of the application:

Each optimization can be relaxed: @Introspected() describes a class completely, aop_prune: false keeps every proxy, and a build property set to true keeps a module in every build. See Options.

See also