Duplicating 10000 cubes with Alt+D: **13.52s -> 2.23s (6x faster)** (Windows, VS2022 Release build, AMD Ryzen 5950X).
Previous code was doing 2N collection syncs when duplicating N objects. New code avoids all the intermediate syncs by using `BKE_layer_collection_resync_forbid` and `BKE_layer_collection_resync_allow`, and then does one `BKE_main_collection_sync` and one+ `BKE_main_collection_sync_remap` for the whole operation. There is some complexity involved where the `Base` things of newly duplicated objects can't be found yet, without the sync, so some work on them (marking them selected, active, ...) has to be deferred until after the sync.
The implementation uses the same "forbit sync" machinery as added & used in D11889. A "much more proper fix" would be to make collection syncs not be expensive at all (T73411), but who knows when that would get implemented.
Timings: scene with 10k cubes, each with unique mesh (Windows, VS2022 Release build, AMD Ryzen 5950X):
- Shift+D duplicate: **13.6s -> 9.2s**
- Alt+D duplicate: **4.76s -> 1.53s**
Most of remaining time is within `BKE_id_new_name_validate`, for which there's a separate optimization T73412 & D14162.