Skip to content
javahacks.dev
Quarkus

Why Quarkus Starts Fast and What Build Time Work Means

Why Quarkus starts quickly: it moves annotation scanning, dependency injection wiring and proxy generation from application startup to the build.

7 min read
Summarize in AI
Flat illustration of a dependency tree and build phases, with the Quarkus, OpenJDK, Gradle and Jenkins logos.

Start a conventional Spring or Jakarta EE application and watch what the first ten seconds are spent on. Nothing in them is your business logic. The framework lists the classes on the classpath, reads their annotations, decides which ones are beans, works out who depends on whom, creates proxies for the ones that need transactions or security and parses the configuration into objects. It does all of that on every start, and it arrives at the same answer every time, because the application did not change between Tuesday's start and Wednesday's. Quarkus asks the obvious question: if the answer is the same, why compute it at startup?

This post explains the idea with a measurement of the cost being avoided, shows what Quarkus generates in its place, and then covers memory, native images, who gains and what you give up. The measurement is a JDK 17.0.1 program on a 10-core laptop. The Quarkus parts describe Quarkus 3, and no full application was benchmarked for this post, so the claim to carry away is the mechanism, not a speed figure.

What a conventional framework does at startup

Runtime frameworks discover the application by reflection. This program imitates the first step of that discovery: it lists the classes in one package tree of the JDK, loads each without initializing it and looks at every method for annotations.

src/main/java/dev/javahacks/startup/Scan.javajava
import java.lang.reflect.Method;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Scan {
    public static void main(String[] args) throws Exception {
        long t0 = System.nanoTime();
        FileSystem jrt = FileSystems.getFileSystem(URI.create("jrt:/"));
        List<String> names;
        try (Stream<Path> s = Files.walk(jrt.getPath("/modules/java.base/java/util"))) {
            names = s.map(Path::toString)
                     .filter(p -> p.endsWith(".class") && !p.contains("-"))
                     .map(p -> p.substring("/modules/java.base/".length(), p.length() - 6).replace('/', '.'))
                     .collect(Collectors.toList());
        }
        long list = (System.nanoTime() - t0) / 1_000_000;

        int methods = 0, annotated = 0;
        t0 = System.nanoTime();
        for (String n : names) {
            try {
                Class<?> c = Class.forName(n, false, Scan.class.getClassLoader());
                for (Method m : c.getDeclaredMethods()) {
                    methods++;
                    if (m.getAnnotations().length > 0) annotated++;
                }
            } catch (Throwable ignored) { }
        }
        long inspect = (System.nanoTime() - t0) / 1_000_000;
        System.out.println("classes=" + names.size() + " list=" + list + " ms, inspect=" + inspect
            + " ms, methods=" + methods + ", annotated=" + annotated);
    }
}
Text
classes=1368 list=34 ms, inspect=63 ms, methods=10906, annotated=92

For 1,368 classes the program spent 34 ms listing and 63 ms inspecting, around 100 ms in total, to learn that 92 of 10,906 methods carry an annotation. That is less than one percent of the work producing the result, and the result never changes. A real application on the classpath includes tens of thousands of classes from its libraries, and the framework reads many more annotations and builds more structure from them than this loop does. The arithmetic is the point: if the cost scaled linearly, which it does not exactly, 20,000 classes would be some one and a half seconds of discovery before a single bean exists. After discovery come dependency resolution, proxy generation (which defines new classes, loading more metadata) and configuration binding.

None of this is a defect in those frameworks. It is the consequence of a design decision made when applications were deployed once and left running: flexibility at runtime was worth a slow start.

What Quarkus moves to the build

Quarkus is organized into extensions, and each extension has a build-time part and a run-time part. When you run the build, the build-time parts do what a conventional framework would do at startup:

  • Index the classes. A Jandex index of annotations and class relationships is built once and stored.
  • Resolve injection. The CDI container, called ArC, decides at build time which bean satisfies every injection point. A missing or ambiguous bean fails the build, not the first request.
  • Generate bytecode. Beans, client proxies and interceptor wrappers are written as ordinary classes. Where Spring creates a proxy with reflection at startup, Quarkus has already compiled it.
  • Read configuration that cannot change. Build-time properties are baked in; only run-time properties are read at startup.
  • Remove what is unused. A bean nothing injects can be dropped, and a library's unused classes never load.

The generated code is not hidden. After a build, look inside the application directory:

Shell
./mvnw package
ls target/quarkus-app/
unzip -l target/quarkus-app/quarkus/generated-bytecode.jar | grep -E "_Bean|_ClientProxy" | head

The generated-bytecode.jar lists classes named like OrderService_Bean and OrderService_ClientProxy. These are the bean definition and the proxy that Spring would have built through reflection on every start. At run time, quarkus-run.jar loads these classes directly. There is no scan and no graph to compute.

You also see the effect in the shape of your code. A Quarkus bean can be a plain class with an annotation, and the container knows at build time everything it needs:

src/main/java/dev/javahacks/orders/OrderService.javajava
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

@ApplicationScoped
public class OrderService {

    @Inject
    OrderRepository repository;       // resolved when the build runs, not when the app starts

    public Order find(long id) {
        return repository.findById(id);
    }
}

Dev mode makes the build-time model cheaper to live with: ./mvnw quarkus:dev rebuilds the affected parts on the next request, see dev mode and continuous testing. For how the build steps themselves work, read build-time processing explained.

Why that saves memory as well as time

Doing the work at startup does not only take time. It leaves its results in memory, and it leaves the machinery used to compute them. A conventional application keeps the annotation metadata it read, the reflection objects (Method, Field, Constructor) it created, the bean definitions and graph, and the classes of the scanning code itself, which loaded just to run once. A Quarkus application never creates most of those, and the classes that would have defined them never load. The resident set of a small service is therefore smaller, and that matters when you run fifty instances per node.

Measure that on your own service with the native memory tracker before believing any vendor chart:

Shell
java -XX:NativeMemoryTracking=summary -jar target/quarkus-app/quarkus-run.jar &
jcmd $(pgrep -f quarkus-run) VM.native_memory summary | grep -E "Total|Class|Metaspace"

The "Class" and metaspace lines show the metadata cost that this architecture reduces, see JVM memory areas.

Native images go further

Build-time knowledge is what makes a GraalVM native image practical. A native image is an ahead-of-time compiled executable: it contains the machine code for exactly the classes the build proves reachable, with no interpreter, no class loader and no JIT. For that analysis to work, reflection, dynamic proxies and resources must be known at build time, which is precisely what Quarkus extensions register for you.

Shell
./mvnw package -Dnative                    # needs GraalVM, or:
./mvnw package -Dnative -Dquarkus.native.container-build=true
./target/orders-1.0-runner

The result starts in tens of milliseconds, uses far less memory at idle, and takes minutes to build with a lot of RAM. When a library does reflection the build did not predict, the failure shows up at run time as a missing class or method, the case in native build reflection failures. Peak throughput of a native executable is generally lower than a warmed-up JIT, which has seen the live profile, see tiered compilation.

Who benefits

The startup advantage matters where processes start often or sit idle:

  • Functions and scale-to-zero workloads, where a cold start is a user-visible delay and you pay per start.
  • Dense deployments, where many small services share a node and memory is the constraint.
  • Autoscaling on short spikes, where the time from decision to ready instance is the time you serve degraded.
  • Command-line tools built with Java, which should feel like any other CLI.

For a service that starts once a week and runs at steady load, startup is a small fraction of its life, and the framework you know well is usually the better choice. A team moving from Spring should read Quarkus for Spring developers before deciding, because the programming model, not the speed, is what you will live with.

What you give up

The bargain has costs, and they are real:

  1. Less runtime magic. Anything that wants to discover and load classes by name at run time, plugins loaded from a directory or a library that scans the classpath on its own, needs an extension or explicit registration.
  2. A longer build. The build does the work startup used to do, plus the generated code. A native build is much longer.
  3. A smaller ecosystem. Libraries must be compatible with the build-time model. Many have extensions; some do not.
  4. Debugging generated code. A stack trace may pass through a generated _Bean class you did not write.

Where the claim does not hold

Fast startup is not fast execution. A JIT-compiled service from any framework reaches a similar steady-state speed, and a Quarkus service on the JVM warms up like any other. If your problem is slow requests, startup architecture will not fix it. If your startup is slow because of a database connection or a DNS timeout, the cause is outside the framework, see slow startup diagnosis. The reasoning behind the design is in the Quarkus philosophy, and the native compilation model is documented in the GraalVM Native Image reference.

Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.