C++ offers S2MemoryTracker for some large operations like S2Builder. This allows clients to set a maximum amount of RAM allocated by an operation and also provides a periodic callback which can trigger an error, e.g. after reaching the deadline of an incoming request.
This second feature is similar to Go's context.Context type. We should consider accepting a Context for operations that a caller might want to cancel if they take too long.