Note: there seems to be one still some O(n2) part in the Purge command, though not that bad one:
The while loop, with comment:
// Add referrer, unless the object to purge is not new
// and the parent is a relation
When purging 176000 ways: needs 20 secs
When purging 550000 ways: needs 260 secs
(in both cases the purged ways are about 99% of the loaded dataset, i.e. not much is left afterwards
and the characteristics of the data is the same - OSM extracts with only buildings in them)
Now I see the reason for this is the same (iteration restarted after every removal, so effectively O(n2) part too), I guess I'll make another patch to fix this one too.