Because making money off your data is their whole business model, they're very motivated to lose as little of it as possible.
Deleting data would not a separate codebase. It would literally be a few different functions that only get called if the country is in the EU.
Do you think they run a separate codebase for google.co.uk and google.fr ?
they have dozens/hundreds of systems in different languages run by different teams. nothing was gdpr compliant 2 years ago. there's been a cost to move to that compliance. changing systems you don't have to is also inefficient. you'd need to weigh the delta between the inefficiencies, assuming that 'efficiency' was the primary goal in the first place.