[WIP] Backport performance fixes