Even if it is a real performance issue, the reasonable fix would be to move the sort call out of the loop - implementing a new data structure in JS is absolutely not the way to fix this.
(Somewhere in the pile of VSCode dependencies you’d think there’d be a generic heap data structure though)