Summary
This PR halves the number of implicit calls to ::find() by using an optimistic approach: insert preemptively, remove in O(1) if already spent.
Motivation
Currently, the ::find() calls that originate from CCoinsViewCache::BatchWrite() account for ~2.9% of total IBD time as shown by this flamegraph from issue #32832
Benchmarks
Benchmarks can't currently measure this change in a realistic manner, because they don't account for cache common related scenarios (see #33375).
This change cannot possibly be a regression since ::try_emplace() is a call to ::find() under the hood. And ::erase(it) is constant time in the worst case.
I'm marking this PR as draft because I ultimately want to measure the impact on a real IBD run.