Tools unable to determine the proper worker count

It is impossible to determine the proper usable CPU count currently.
This leads to problems like here: https://github.com/facebook/create-react-app/issues/4870

When building a react-native app this is very problematic as the process easily crashes without any error message because of an out of memory error.

The code responsible for getting the worker count in RN is here: https://github.com/facebook/metro/blob/fadc316162eb3a46114deccdc3b3230ca4dd41ae/packages/metro/src/lib/getMaxWorkers.js#L13
The same applies to gradle. It also has a worker count of 36.

My current workaround is the following:

const defaultConfig = require('./metro.config.js')
module.exports = {
  ...defaultConfig,
  maxWorkers: process.env.TOTAL_CPUS || 1, /* CircleCI: The issue with this on Dockerized services such as CircleCI is
                                              that the container thinks it has access to all of the hosts cores,
                                              although its being limited down to 4 by another process.
                                              https://github.com/facebook/create-react-app/issues/4870 */
  cacheStores: []
}

and:

environment:
  TOTAL_CPUS: 3 # For class medium+