Cppless: Single-Source and High-Performance Serverless Programming in C++

Marcin Copik, Lukas Möller, Alexandru Calotoiu, Torsten Hoefler · DOI

TL;DR

This paper introduces Cppless, a novel framework that enables C++ developers to seamlessly integrate serverless functions into their applications. By extending the C++ compiler, Cppless automates the deployment and invocation of these functions, allowing for significant performance gains and cost reductions without requiring extensive code modifications or a shift to interpreted languages.

What Problem Does This Paper Address?

Serverless computing, or Function-as-a-Service (FaaS), offers immense scalability and cost-efficiency, making it attractive for various workloads. However, its adoption in the C++ ecosystem has been hindered by several challenges:

  • Complex Deployment: C++ applications require manual separation of functions, separate compilation, and deployment to cloud platforms using vendor-specific interfaces, which is cumbersome and error-prone.
  • Lack of Native Integration: Unlike interpreted languages with built-in reflection and serialization, C++ lacks mechanisms to automatically extract and deploy function code, leading to a fragmented development experience.
  • Type Safety and Serialization: The need to convert strongly-typed C++ data structures to loosely-typed formats like JSON for serverless functions introduces complexity, potential errors, and runtime overhead.
  • Vendor Lock-in: Existing solutions often tie developers to specific cloud providers and their proprietary APIs.

These issues create a high barrier to entry for C++ developers wanting to leverage serverless for high-performance computing tasks, despite C++'s prevalence in such domains.

Methods

Cppless tackles these challenges by introducing a single-source programming model and an end-to-end compiler built on top of the LLVM framework. Key innovations include:

  • Alternative Entry Points: A compiler extension that allows a single C++ translation unit to generate multiple compilation targets: one for the host application and others for serverless functions. This is achieved by treating serverless functions as "alternative entry points" that are compiled separately.
  • Lambda Reflection: A compile-time reflection mechanism for C++ lambda functions. This allows Cppless to inspect and serialize captured variables, enabling the transfer of stateful lambdas to serverless environments.
  • Automatic Deployment: Cppless automates the process of packaging, deploying, and configuring serverless functions to cloud platforms (demonstrated with AWS Lambda). This is managed through a custom deployment tool and CMake extensions.
  • Serialization Library: Integration with the cereal library for efficient serialization of C++ data structures, supporting both JSON and binary formats.
  • Dispatcher Interface: A user-friendly API that abstracts away cloud provider complexities, allowing users to dispatch tasks to serverless functions and wait for their results.

Datasets

Not discussed in the paper. The paper focuses on microbenchmarks and case studies using synthetic workloads and existing applications.

Key Insights and Ideas

  • Bridging the Gap: Cppless demonstrates that C++'s static typing and compilation strengths can be effectively combined with the elasticity and cost-efficiency of serverless computing, without sacrificing developer productivity.
  • Compiler as the Enabler: By leveraging compiler extensions (alternative entry points, lambda reflection), Cppless automates complex deployment and serialization tasks, hiding them from the end-user.
  • Performance vs. Cost Trade-offs: The paper highlights how serverless can offer significant speedups for compute-intensive tasks at a minimal cost increase, especially when compared to maintaining dedicated virtual machines.
  • Fine-grained Resource Allocation: Cppless's ability to deploy each function independently allows for fine-grained resource allocation (memory, CPU), leading to better efficiency for diverse workloads compared to monolithic serverless functions.

Key Results

  • Speedup: Achieved up to 59x speedup in a CPU Ray-Tracing benchmark and up to 144x speedup in an N-Queens benchmark compared to local execution.
  • Cost Efficiency: For the PI approximation benchmark, offloading with Cppless resulted in a 500.4x larger cost than using only one function at 512 functions, but this was still significantly cheaper than maintaining a VM for the same workload. The total cost for serverless functions increased by only 6% for a 54.8x decrease in processing time in the Ray-Tracing benchmark.
  • Cold Start Overhead: C++ functions exhibit minimal cold start overhead (10-12 ms), significantly lower than Python functions, especially when numerical libraries are involved.
  • Code Modifications: Implementing serverless offloading with Cppless required minimal code changes (e.g., 7 lines of configuration and 18 lines of serialization instructions for a Pi estimation task).

Limitations and Future Work

  • Serializable Function Objects: Cppless currently requires tasks to be serializable function objects. Support for constant function pointers is a potential area for improvement.
  • Entry Point Interface: The current implementation assumes an executable deployment model, which might not be suitable for all serverless platforms. Generating shared libraries is a suggested alternative.
  • Selective Compilation: Cppless generates full code for each alternative entry point. Techniques for selective compilation could reduce binary sizes.
  • Captured Variables: Non-local (global) variables are not supported in lambda captures. Future work could involve compiler analysis to identify and handle these.
  • Zero-Copy and Serialization-Free Data Transfer: Cppless relies on serialization for data transfer. Exploring zero-copy mechanisms or improved serialization-free data transfer could further enhance performance.
  • Fault Tolerance: Fault tolerance is currently the user's responsibility. Extending Cppless to catch exceptions and provide error information is a planned enhancement.
  • Platform Support: While demonstrated with AWS Lambda, extending support to other platforms (e.g., Google Cloud Functions via WebAssembly) is a future direction.

Summary updated

BibTeX
@article{copik2025cppless,
  author = {Marcin Copik and Lukas Möller and Alexandru Calotoiu and Torsten Hoefler},
  title = {{Cppless: Single-Source and High-Performance Serverless Programming in C++}},
  journal = {ACM Trans. Archit. Code Optim.},
  year = {2025},
  doi = {10.1145/3747841},
}
Figure