Optimization strategies
Use prebuilds
Prebuilds run your environment setup ahead of time: container builds, dependency installation, and startup tasks. When an environment starts, it loads from a prebuild snapshot instead of running setup from scratch. This is the single biggest optimization. Configure prebuilds to run on a daily schedule before your team or agents start work. You can also run a prebuild manually after important dependency or setup changes.Enable Dev Container image caching
For runners in your VPC, enable image caching to avoid rebuilding containers:- AWS runners: Caches built Dev Container images automatically
- GCP runners: Supports image caching through Artifact Registry
Optimize your Dockerfile
Structure your Dockerfile for caching efficiency:- Put stable dependencies first: System packages, build tools, and runtimes that rarely change should be early in the Dockerfile.
- Put volatile dependencies last: Application dependencies that change frequently go at the end.
- Use prebuilt base images: Push your base image to a registry and reference it in
devcontainer.json.
Use tasks for dynamic setup
For setup that must happen at runtime (database seeding, environment-specific config), use Tasks rather than baking everything into the image.Use one environment per task
Create a fresh environment for each piece of work rather than reusing environments across tasks. This matches how agents operate:- Agent receives a task
- Agent starts a clean environment
- Agent completes the work and creates a PR
- Environment is discarded
- No state conflicts: Each task gets a clean slate
- Parallel execution: Multiple agents work simultaneously without interference
- Mistakes are free: If something goes wrong, discard the environment and start fresh
Measure startup time
Track these metrics to identify bottlenecks:- Container build time: How long does the Dev Container image take to build?
- Dependency installation: How long do startup tasks take to run?
- Prebuild freshness: Are prebuilds running often enough to stay current?