Context: Unity CI/CD build environment isolation at VARLab
Problem: Unity Editor 100% CPU usage causing server crashes on concurrent builds
Solution: Azure Batch + Spot VMs for on-demand execution
Result: 94.88% infrastructure cost reduction ($618 → $32 for 56 days)
| Metric | Before | After |
|---|---|---|
| Build environment | Shared CI/CD server | Isolated cloud containers |
| Concurrent builds | Server crash risk | Parallel execution safe |
| Cost model | 24/7 VM running | Pay-per-use |
| Cost reduction | - | 94.88% |
Problem: Unity Editor provides no CPU usage control during builds. When 2+ projects build simultaneously, the CI/CD server crashes.
Root Cause Analysis:
Solution: Trade-off approach — maintain project files & artifacts (skip “from scratch” builds), set optimization level to 0 (skip optimization phase).
Result: Reduced initial compile time from 10 min → 1 min, prevented server crashes.
Goal: Eliminate the trade-off from Phase 1 — enable clean builds without sacrificing speed.
Solution 1: Docker containerization with CPU allocation — enabled concurrent builds without crashes.
Solution 2: PID-level profiling + Unity settings optimization — analyzed CPU usage at 5-second intervals, tuned emscriptenArgs, Il2CppCodeGeneration, managedStrippingLevel, etc.
| Metric | Before | After |
|---|---|---|
| Clean build time | 13-14 min | 7.4 min (47% faster) |
| Build size | 146 MB | 95.2 MB (35% smaller) |
Limitation: Still running on the same CI/CD server.
Proactive Initiative: Docker containerization in Phase 2 proved builds could run in isolated environments. This raised a question: if containers can run independently, why not leverage cloud infrastructure for parallel, on-demand execution?
Solution: Azure Batch + Spot VMs — completely separated Unity build/test environment from CI/CD server. On-demand ephemeral containers, pay only for actual compute time.
| Strategy | Cost (56 days) | vs Always-On |
|---|---|---|
| Always-On VM (24/7) | $618.24 | baseline |
| Deallocated VM (job-triggered) | $144.60 | -76.6% |
| Azure Batch + Spot VMs | $31.64 | -94.88% |
Analysis Period: May 5 - June 29, 2025 (56 days, 37 active days) | Projects: 2 Unity VR projects (855 CI jobs, 166 CD jobs)