Title
Add mmap-backed Polynomial allocation gated on BB_SLOW_LOW_MEMORY
Motivation
On memory-constrained mobile targets (e.g. zkPassport on iOS/Android) the RAM footprint of large proving keys and working polynomials is the main source of crashes. We already proved in a local PoC that mapping polynomials to disk with mmap slashes resident memory while keeping the API intact.
What & How
-
Compile-time gate:
#ifdef BB_SLOW_LOW_MEMORY
// new mmap-backed storage
#else
// current heap allocation path
#endif
-
Behavior:
- When
BB_SLOW_LOW_MEMORY is defined every Polynomial instance is backed by its own anonymous temporary file created with O_TMPFILE (or mkstemp + unlink fallback).
- Outside that build flag nothing changes ― the class stays purely in-memory.
-
Details / Notes
mmap(size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)
- RAII cleanup:
munmap in the destructor; file closes automatically because it’s unlinked right after creation.
- Keep constructor, iterators, and operator[] unchanged so existing call-sites compile untouched.
Acceptance criteria
- Allowing for significant slowdown, ability to run in a memory-constrained docker environment (e.g. say 1GB for a proving job that normally takes 2GB). This is a proxy for showing that mobile devices will evict pages as needed to keep our app within memory.
Potential followups
- Use
madvise? (dubious if needed, complicated)
Title
Add mmap-backed
Polynomialallocation gated onBB_SLOW_LOW_MEMORYMotivation
On memory-constrained mobile targets (e.g. zkPassport on iOS/Android) the RAM footprint of large proving keys and working polynomials is the main source of crashes. We already proved in a local PoC that mapping polynomials to disk with
mmapslashes resident memory while keeping the API intact.What & How
Compile-time gate:
Behavior:
BB_SLOW_LOW_MEMORYis defined everyPolynomialinstance is backed by its own anonymous temporary file created withO_TMPFILE(ormkstemp+unlinkfallback).Details / Notes
mmap(size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)munmapin the destructor; file closes automatically because it’s unlinked right after creation.Acceptance criteria
Potential followups
madvise? (dubious if needed, complicated)