Site freezes when trying to edit segment with 40k contacts

Your software
My Mautic version is: 3.3.5
My PHP version is: 7.3.29
My Database type and version is: Mysql 5.x

Your problem
My problem is:
I have a segment with 40k emails assigned to a campaign. When I try to edit the segment to assign it to a campaign the site freezes and I get an error 503. The machine is a n1-standard-1 with 1 vCPU and 3.75 GB RAM.

These errors are showing in the log:
I’m getting an error 503 timeout

Steps I have tried to fix the problem:
I have upgraded the server up to 2 vCPU and 16GB RAM