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

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

TL;DR

Cppless is a new end-to-end framework that brings the "single-source" programming model—familiar to GPU developers using CUDA or SYCL—to the world of serverless computing. By extending the LLVM/Clang compiler, it allows C++ developers to offload compute-intensive tasks to the cloud with just a few lines of code, achieving up to 59x speedups while automating the complex deployment and serialization processes that usually make C++ a headache in serverless environments.

What Problem Does This Paper Address?

Serverless computing (Function-as-a-Service or FaaS) is incredibly scalable and cost-effective, but it has a "C++ problem." While interpreted languages like Python and JavaScript dominate the field because they are easy to deploy and can extract code at runtime, C++ developers face three major hurdles:

  1. Compile-Time Dispatch: C++ is compiled ahead-of-time. Splitting a single application into a "host" part and multiple "cloud function" parts usually requires manual code separation and complex build pipelines.
  2. Environment Mismatches: Your local machine (e.g., an ARM-based MacBook) might have a completely different architecture and set of system libraries (ABI) than the cloud environment (e.g., an x86 Linux container).
  3. Static vs. Loose Typing: Cloud platforms communicate via loosely typed JSON, while C++ relies on strong, static types. Converting between the two is error-prone and slow.

As a result, C++ is rarely used for serverless, despite its massive performance advantages for compute-heavy tasks like scientific analysis or machine learning.

Methods

The authors built Cppless on top of the LLVM/Clang toolchain. The framework introduces two clever compiler extensions to bridge the gap between local code and cloud functions:

  • Alternative Entry Points: Traditionally, a C++ program has one main() function. Cppless allows a single source file to define multiple entry points. The compiler "splits" the compilation path, generating a separate executable for every function marked for the cloud.
  • Lambda Reflection: C++ lambdas are "anonymous" and their internal state (captured variables) is hidden. Cppless extends the compiler to allow reflection, enabling the framework to automatically "peek" inside a lambda, read its captured data, and serialize it for transmission to the cloud.

The workflow is illustrated in Figure 1, showing how Cppless moves from a single source file to automatic deployment.

![Fig.

  1. Compilation in Cppless: single-source programming with automatic deployment at compilation time.](/figures/art_ec9912b6235c43f1a69e1f35485f62b1)

To handle data transfer, Cppless uses the cereal library for serialization, favoring a binary-to-Base64 format that is significantly faster than standard JSON. The entire process is integrated into CMake, meaning a developer can deploy their cloud functions simply by running their standard build command.

Datasets

The authors evaluated Cppless using several compute-intensive benchmarks:

  • Monte Carlo Pi Estimation: A classic parallelizable task used to test weak and strong scaling.
  • N-Queens (from the BOTS suite): A combinatorial problem used to evaluate how the framework handles varying workloads.
  • CPU Ray-Tracing: A complex, real-world application involving nine translation units and polymorphic types.
  • SeBS Benchmark Suite: Specifically, C++ ports of image thumbnailing, image recognition (ResNet-50/Torch), and graph processing (Pagerank).

Key Insights and Ideas

  • The "Single-Source" Advantage: By keeping the host and function code in one file, developers maintain type safety and avoid the "code bloat" of managing multiple projects.
  • Cold Start Superiority: One of the most surprising findings is that C++ functions have much lower "cold start" overhead (~10-12ms) compared to Python (which can be 10x to 50x slower). This makes C++ viable for much more fine-grained, short-lived tasks.
  • Binary Serialization is Essential: The authors found that standard JSON serialization is a massive bottleneck. Their custom binary format is up to 8x faster than vanilla JSON, which is crucial when every millisecond in the cloud costs money.
  • Heterogeneous Scaling: Cppless allows developers to configure memory and CPU resources independently for each offloaded function, preventing the "one-size-fits-all" waste common in other frameworks.

Key Results

  • Speedup: In the Ray-Tracing case study, Cppless achieved a 59x speedup by offloading tiles to 544 parallel serverless workers.
  • Productivity: For the Ray-Tracer, moving from a standard multithreaded implementation to a serverless one required only 7 lines of offloading code and 18 lines of serialization instructions.
  • Cost Efficiency: For bursty workloads, Cppless proved significantly cheaper than keeping a dedicated virtual machine (VM) running. For example, a Ray-Tracing task that would take minutes to boot on a VM was delivered in one second for less than $0.0027.

The development workflow, from compilation to runtime invocation, is summarized in Figure 2.

Development workflow in serverless: functions are shipped to the cloud during deployment. At runtime, the main applications invoke previously created functions.

Limitations and Future Work

The authors identify several areas for improvement:

  • Pass-by-Value Only: Currently, Cppless only supports passing arguments by value. It cannot handle variables captured by reference, which prevents issues with dangling pointers in an asynchronous cloud environment but limits some C++ patterns.
  • Global Variables: Functions cannot access global variables because they aren't part of a lambda's capture list.
  • Compilation Time: Because the compiler effectively builds a new executable for every cloud function, build times increase linearly with the number of offloaded functions.
  • Future Directions: The authors suggest that future versions of C++ (like C++26) might include native reflection, which would allow Cppless to work as a simpler source-to-source translator rather than requiring deep compiler patches. They also aim to support WebAssembly (Wasm) targets for even broader cloud compatibility.

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