The inner loop was way too long; split out most of the heavy lifting around backrefs and tombstones into a helper function.
ostree-boot-complete.service