High memory consumption during native extension build
Description
Building native extensions requires up to 31 GB of RAM (about 16gb per process) even with reduced parallelism (CMAKE_BUILD_PARALLEL_LEVEL=2). This makes installation difficult or impossible on machines with limited memory.
It would be helpful to have an option (e.g. a CMake preset or build flag) that reduces memory usage during compilation and linking — for example by using a more memory-efficient linker like mold, limiting link-time parallelism, or splitting large link steps.
Environment
- OS: Ubuntu 23.04 (kernel 6.2.0-39-generic)
- CMake: 4.2.3
- Ruby: 4.0.1 (2026-01-13 revision e04267a14b) +PRISM
- RubyGems: 4.0.3
- GCC: 12.3.0
- RAM: 32 GB total
Steps to reproduce
CMAKE_BUILD_PARALLEL_LEVEL=2 PATH=/snap/bin:$PATH gem install opencv-ruby -- --preset linux-release
Monitor memory during build:
Observed behavior
Memory usage peaks at ~31 GB during the build, even with CMAKE_BUILD_PARALLEL_LEVEL=2. The system also has 4.2 GB of swap in use, indicating significant memory pressure.
Expected behavior
A low-memory build preset or documented flags to reduce peak memory consumption, or documentation on how to tune the build for memory-constrained environments
High memory consumption during native extension build
Description
Building native extensions requires up to 31 GB of RAM (about 16gb per process) even with reduced parallelism (
CMAKE_BUILD_PARALLEL_LEVEL=2). This makes installation difficult or impossible on machines with limited memory.It would be helpful to have an option (e.g. a CMake preset or build flag) that reduces memory usage during compilation and linking — for example by using a more memory-efficient linker like
mold, limiting link-time parallelism, or splitting large link steps.Environment
Steps to reproduce
CMAKE_BUILD_PARALLEL_LEVEL=2 PATH=/snap/bin:$PATH gem install opencv-ruby -- --preset linux-releaseMonitor memory during build:
watch -n 2 'free -h'Observed behavior
Memory usage peaks at ~31 GB during the build, even with
CMAKE_BUILD_PARALLEL_LEVEL=2. The system also has 4.2 GB of swap in use, indicating significant memory pressure.Expected behavior
A low-memory build preset or documented flags to reduce peak memory consumption, or documentation on how to tune the build for memory-constrained environments