This caches g_UnitActions sorted, which was computed in input.js on every tick. Since g_UnitActions does not change in the progress of a game it can be cached upon init.
Relevant timing differences:
- Init: From non-existent to ~130 microseconds.
- OnTick (and mouse movement): From ~100 to ~5 microseconds.
Why this is bad:
- It introduces another global variable.
(I would say we can just sort g_UnitActions itself, for we have no need of the unsorted variant?)< Not possible.
Why this is good:
- It speeds up determineAction in input.js significantly.