Skip to content

High memory consumption during native extension build #5

Description

@4dreadhead

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:

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions