Proto-Faaslets are a way to restore the execution state of a function without rerunning the code that got it to that state.
Proto-Faaslets mean we can snapshot a function when it's running, then restore it later, resuming its execution. The same proto-function can be restored multiple times and across different hosts.
Proto-Faaslets can be used to reduce function cold starts by:
- Running initialisation code once when the function is uploaded
- Creating a proto-function after this function has been run
- Restoring all subsequent function calls from this snapshot
Any slow or resource-intensive initialisation that would otherwise be performed on every call can be captured in this proto-function snapshot, thus repeatedly saving on overheads.
Proto-Faaslets can be defined in C/C++ with the FAASM_ZYGOTE
macro:
#include "faasm/faasm.h"
int myGlobal;
FAASM_ZYGOTE() {
// Run once
myGlobal = 5;
return 0;
}
FAASM_MAIN_FUNC() {
// Context available to all subsequent function calls
printf("My global = %i\n", myGlobal);
return 0;
}
Proto-Faaslets are also used in Faasm to migrate functions across hosts.