improve id compaction performance

Just record a list of swaps, then rebuild the indexes. There is no need to swap
each node individually.