When deleting a project, currently, deletion of permissions (both user and group) is performed for every components in the project (same for views). As a consequence, multiple SQL requests are sent to delete data from permission tables(one for every 1000 components in the project).
The fact is that permissions can only be defined at project/view level. The number of SQL request could be therefor reduced to just one per table, a very much simpler ones.
To avoid having data left over in the database with this new method which have been deleted by the old one, a database migration should be added to delete any permission defined for components which are neither projects nor views.