Hi. My summary of the problem is that this package uses too much RAM per CPU, i.e. the ratio UsedRAM / AvailableCPUs is a lot higher than in most packages.
I can think of two ways to fix this: A) The simple and effective way: Disable parallel building, i.e. add --no-parallel to dh call. The package would still build the same, and it would not sacrifice things like -O3, which would be preserved. If this package had a build time much lower than it has, I believe that would be the best solution. However, this package takes its time to build, in such a way that parallel building makes a difference, and I understand if you don't like the simple and effective solution. B) The not so simple but also effective way. This package is not the first one having a problem with RAM/CPU ratio. Other packages have implemented solutions in debian/rules to reduce the number of CPUs used according to available RAM. For example, the llvm-toolchain-NN packages do this: https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/-/blob/17/debian/rules?ref_type=heads#L60-67 I would be willing to propose a patch like that. Would you consider it? (In case you don't like solution A, that is). Thanks.