The synchronization could be reduced a bit here by copying the dictionary, emptying it immediately, and then saving everything outside of `@synchronized`.