Checking whether templates exist goes through the VFS, which is generally kinda slow (probably worse in dev builds). We should cache these. Note that we could reuse the loaded templates on the C++ side, but that actually won't cache bad-entities (such as Apadana for mace for example).
Storing it in the JS component like that seems neat, is performant, and resists nicely to hotloading and reloading games.
The MP safety assumes that the VFS doesn't change mid-game, but I think that's safe enough.
To profile this, you need to be in visual mode and select units that can build stuff. You also need to 'refresh' the selection, by e.g. having some selected units die.