Skip to content

Commit

Permalink
Use JSON.parse for parsing teambuilder tables (smogon#1714)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KamilaBorowska authored Jan 23, 2021
1 parent 934eb7b commit 0005f1f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion build-tools/build-indexes
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 0005f1f

Please sign in to comment.