Use JSON.parse for parsing teambuilder tables (#1714)

This optimizes JavaScript parsing performance. V8 developers
recommend applying this optimization for objects of 10 kB or
larger, see <https://v8.dev/blog/cost-of-javascript-2019#json>
for more details. Teambuilder tables are 3.5 MBs which is much
more than 10 kB.
This commit is contained in:
Konrad Borowski 2021-01-23 18:45:20 +01:00 committed by GitHub
parent 934eb7be2c
commit 0005f1f79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1018,7 +1018,7 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
}
}
buf += 'exports.BattleTeambuilderTable = ' + JSON.stringify(BattleTeambuilderTable) + ';\n\n';
buf += `exports.BattleTeambuilderTable = JSON.parse('${JSON.stringify(BattleTeambuilderTable).replace(/['\\]/g, "\\$&")}');\n\n`;
fs.writeFileSync('data/teambuilder-tables.js', buf);
}