I'm currently implementing an emulator in Javascript, the memory model of the emulated platform is rather complex, so I'm having my reads and writes go via an array of functions, for example:
var MRead = [];
ReadBiosSpace = function(addr) { return (EnableBios ? BIOS[addr] : ROM[addr]); };
for (i = 0; i <= 0xFF; i++) { MRead[i] = ReadBiosSpace; };
function Read(addr) { return MRead[addr](addr); };
because obviously the Read and Write functions will be called extremely often (at least once per instruction, the main execution is Operators[Read(ProgramCounter)]()
) they are extremely performance sensitive.
Are there any performance optimizations that can be done? is this the best method?