I have been experimenting with the Memory object for awhile. I decided to modify the JSON.parse and JSON.stringify method to see when Screeps was parsing and stringifying Memory:
let stringify = JSON.stringify;
JSON.stringify = (object) => {
if(object === Memory) {
console.log("stringifyed Memory");
}
return stringify(object);
};
let parse = JSON.parse;
JSON.parse = (string) => {
//closest way to checking if the string being parsed is Memory.
//should work for any Memory that is correctly formatted.
if(parse(string).creeps) {
console.log("parsed Memory");
}
return parse(string);
}
module.exports.loop = function () {
//Memory is referenced to cause Screeps to perceve memory as active
Memory;
}
each tick the probe code posts this to the console:
[shard3] parsed Memory
[shard3] stringifyed Memory
Business as normal right? Here is the issue: variables can be loaded before the game loop on startup. There is no reason Screeps should parse the Memory each tick. Memory could be parsed before the game loop, then stringifyed each tick. it would get the job done without as much overhead.
Is there any reason that the Memory has to be parsed each tick? If so I would be curious to know why.