You could simply calculate the sum with Apex (instead of relying on the SOQL query to do it for you), but in this case it looks like you can probably re-arrange your query so that there is no inner query.
So instead of
SELECT Id, (SELECT Id FROM Children__r) FROM Parent WHERE Id IN :parentIds
You can base the query off of your child object
SELECT Id FROM Child WHERE ParentId IN :parentIds
Since the information you're looking to gather is now the only part of the query, you can use COUNT()
and GROUP BY
SELECT COUNT(Id), ParentId FROM Child WHERE ParentId IN :parentIds GROUP BY ParentId
The big thing to be aware of is that you'll only get a count for parent records that have at least one child record. If you want to be able to update the parent record when it loses its last child, you'll want to iterate through the parent Ids and populate a Map with a record with a default value (like 0).
Map<Id, Parent> parentsToUpdateMap = new Map<Id, Parent>();
for(Id parentId :parentIds){
parentsToUpdateMap.put(parentId, new Parent(Id = parentId, Count__c = 0));
}
for(AggregateResult ar :/* aggregate query here */){
parentsToUpdateMap.get((Id)ar.get('ParentId')).Count__c = (Integer)ar.get(<something like 'expr0' or the field alias in your SOQL>);
}
update parentsToUpdateMap.values();