"Prevent sharing a project within ${GROUP} with other groups" times out for large group hierarchies

Summary

A SaaS customer with a large group hierarchy is unable to click the "Prevent sharing a project within ${GROUP} with other groups" checkbox under Settings > General > Permissions, LFS, 2FA; it times out / error 500s.

Steps to reproduce

Create a large group hierarchy with tens of thousands of projects, thousands of subgroups and add thousands of users. Attempt to enable "Prevent sharing a project within ${GROUP} with other groups"

Example Project

https://gitlab.my.salesforce.com/00161000004zoBW

What is the current bug behavior?

An error 500 page is shown