The Green Shift: Transitioning .NET Services Across Architectures • Sara Bergman • GOTO 2025
Sara Bergman presents a practical guide on migrating .NET services to ARM-based architectures to achieve significant energy efficiency, cost savings, and performance per watt. She details the advantages of RISC over CISC, offers real-world examples, and provides a step-by-step .NET migration journey, emphasizing the importance of staying current with .NET, leveraging compilers, and strategically integrating ARM into development and deployment pipelines.
Sara Bergman, a Senior Software Engineer at Microsoft and co-author of “Building Green Software,” presents a practical guide on transitioning .NET services to ARM-based platforms. Her work focuses on cloud-scale CPU/GPU efficiency and advocating for green software practices, which she defines as creating carbon-efficient software. This entails treating carbon as a scarce resource and optimizing its use across three key areas: ## 1. Energy Efficiency This is the primary focus of the talk. Bergman emphasizes that energy efficiency is crucial because servers exhibit high energy proportionality, meaning they consume substantial static power even when idle. The goal is to maximize utilization to reduce this initial “startup cost” of power consumption, thus lowering both monetary and carbon costs. ## 2. Hardware Efficiency Using the least amount of hardware is paramount. Hardware production is highly carbon-intensive, involving extensive mining, shipping, and energy-intensive manufacturing processes, resulting in a significant “carbon debt” for each new device. Engineers should aim to use existing hardware for its full lifespan and deploy fewer machines overall. This is where the architectural shift to ARM becomes highly relevant. ## 3. Carbon Awareness This principle involves scheduling computational workloads to align with periods when electricity grids are powered by cleaner, renewable energy sources. While not the main focus, Bergman highlights the global boom in renewable energy as a hopeful sign, stressing that diligent energy stewardship remains critical until clean, abundant energy is universally available. ## CPU Architectures: RISC vs. CISC The presentation delves into the fundamental differences between Reduced Instruction Set Computers (RISC), exemplified by ARM, and Complex Instruction Set Computers (CISC), like x86/x64. Historically, there was a “RISC vs. CISC war,” and Bergman notes that the industry is currently experiencing an inflection point swinging back towards RISC. * RISC (ARM): Characterized by a smaller, simpler set of fixed-length instructions. This allows for faster execution per instruction, though potentially larger code size. ARM chips have simpler hardware, fewer transistors (which consume power), and are inherently designed for power efficiency, often optimized extensively via compilers. Their traditional strongholds include mobile, embedded systems, and increasingly, cloud environments. * CISC (x86/x64): Features larger, complex, variable-length instructions, leading to slower execution per instruction but potentially smaller code size. CISC hardware is more complex with more transistors, consuming more power. Optimizations are typically more hardware-centric. Traditional domains include desktops, servers, and legacy systems. ## Why Migrate to ARM? The “Trifecta of Green Wins” Bergman presents compelling real-world examples and the widespread adoption by cloud providers to illustrate the benefits of ARM: * Industry Examples: Cloudflare saw 1.57 requests per watt on Ampere ARM versus 1.0 on x86. Amadeus on Azure achieved 37-47% price-performance improvement. Siemens experienced a 20% performance boost with Azure Cobalt. * Cloud Provider Support: All major cloud providers—AWS (Graviton, since 2018), Azure (Cobalt, 2024), and Google (Axion, 2024)—now offer their own ARM-based chips. These translate into a “trifecta of green wins”: 1. Power Efficiency: ARM processors are inherently designed for power-constrained environments, consuming significantly less energy for equivalent workloads. 2. Cost Savings: ARM-based instances are often offered at lower price points by cloud providers, and their superior performance per watt means fewer instances are needed to handle the same workload. 3. Performance per Watt: This metric, representing “useful work out of every unit of energy,” is where ARM excels due to its simpler architecture, fewer transistors, and higher core counts. Modern ARM chips, like those from Ampere, are designed to perform optimally at very high utilization (80-90%), offering substantial throughput per watt. ## Hardware Efficiency: Less is Greener The speaker reiterates that efficient ARM hardware translates to higher throughput from fewer physical machines, reducing both the initial carbon debt and ongoing operational energy costs. * Caveats: * Avoid “Lift and Shift”: Merely moving existing workloads to ARM VMs without optimizing (e.g., containerizing, right-sizing) limits the benefits. Allowing cloud providers to manage container packing on physical hardware maximizes efficiency. * On-Prem Strategy: For on-premise environments, immediate wholesale replacement of x86 servers with ARM is discouraged due to the embodied carbon of existing hardware. A gradual replacement strategy, running existing servers to end-of-life, is greener. * “Any CPU” Architecture: Designing services to run on any CPU architecture (x64 or ARM64) allows for flexibility, cost optimization by utilizing “scrap compute,” and agility in adapting to new cloud trends. * Specialized Chips: While hardware-specific accelerators can boost performance, they require significant software development effort, which might offset the benefits if not carefully considered for specific performance-critical applications. ## The .NET Migration Journey to ARM Bergman confirms that .NET is ready for ARM64, with first-class cross-platform and cross-architecture support since .NET 6. While core .NET SDKs and runtimes are compliant, developers may encounter gaps with native dependencies, third-party libraries, and certain tooling. The central tenet for migration is to “let the platform do the heavy lifting”: * Stay Up-to-Date with .NET: Regular updates to the latest .NET versions provide “free” performance and efficiency gains, including ARM-specific optimizations. * Leverage Compilers: Focus on writing clean, idiomatic code and rely on the highly sophisticated .NET compilers and their flags (e.g., profile-guided optimizations) for micro-optimizations, rather than manual, time-consuming efforts. The practical migration journey involves these steps: * Building and Compiling: Set PlatformTarget to AnyCPU in .csproj files to make managed code architecture-neutral. * Installation and Running: Install the .NET SDK directly on an ARM machine. A simple dotnet build and dotnet run should work. * DLL vs. EXE: Be mindful that DLLs inherit the runtime architecture from the hosting process, while EXEs are architecture-specific. Building an EXE on x64 for x64 will result in emulation on an ARM processor. For optimal performance, build EXEs directly on ARM for ARM. * Multiple Runtime Identifiers (RIDs): Utilize RIDs for platform-specific builds, especially when dealing with native dependencies or NuGet packages, explicitly specifying the target RID during publication. * Testing: It’s crucial to have at least one ARM64 environment outside of production (e.g., a dedicated testing environment or CI/CD runner) to catch subtle architectural differences early. * Native Dependencies: Libraries written in unmanaged code (C/C++) require recompilation for ARM64 or replacement. Docker with QEMU can aid cross-compilation. * OS Compatibility: Verify that the chosen OS image has good ARM64 support and check for hard-coded OS assumptions in the code. * Benchmarking: Crucially, benchmark your actual workload and application behavior, not just generic CPU stress tests, to gain relevant insights into performance, cost, and carbon benefits. * Deployment: Modify CI/CD pipelines to target ARM. Both GitHub Actions and GitLab offer ARM64 support. Cross-compilation from x64 to ARM64 is possible with explicit RuntimeIdentifier parameters, often aided by Docker. Emulation of x64 processes on ARM can offer quick financial wins but compromises performance. * Measurement and Optimization: After deployment, monitor latency, throughput (aim for improvement), vCore/VMN counts (aim for reduction), and cloud bills. Further fine-tuning for ARM-specific hardware capabilities can yield additional benefits, though it may reduce the “any CPU” flexibility. ## Key Takeaways: Bergman concludes by urging the adoption of ARM/RISC architectures for superior performance per watt. She emphasizes letting platforms (modern .NET, cloud providers, compilers) handle optimizations, as sustainability and energy efficiency are poised to be major drivers of future processor design innovation.