Improve performance of `mark_as_sent_devices_by_remote`.