Skip to content

Commit

Permalink
Data: stopgap perf bug fix in
Browse files Browse the repository at this point in the history
Previously computed whole move pool just to see whether it's empty. It accounts for about 25% of the test suite runtime.
  • Loading branch information
larry-the-table-guy committed Oct 13, 2024
1 parent ca27f79 commit e2f57ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data/random-battles/gen9/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1988,7 +1988,7 @@ export class RandomTeams {
for (const species of speciesPool) {
if (species.isNonstandard && species.isNonstandard !== 'Unobtainable') continue;
if (requireMoves) {
const hasMovesInCurrentGen = this.dex.species.getMovePool(species.id).size;
const hasMovesInCurrentGen = this.dex.species.getMovePool(species.id, false, 1).size;
if (!hasMovesInCurrentGen) continue;
}
if (requiredType && !species.types.includes(requiredType)) continue;
Expand Down
6 changes: 5 additions & 1 deletion sim/dex-species.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,13 @@ export class DexSpecies {
/**
* @param id the ID of the species the move pool belongs to
* @param isNatDex
* @param sizeLimit 0 for all
* @returns a Set of IDs of the full valid movepool of the given species for the current generation/mod.
* Note that inter-move incompatibilities, such as those from exclusive events, are not considered and all moves are
* lumped together. However, Necturna and Necturine's Sketchable moves are omitted from this pool, as their fundamental
* incompatibility with each other is essential to the nature of those species.
*/
getMovePool(id: ID, isNatDex = false): Set<ID> {
getMovePool(id: ID, isNatDex = false, sizeLimit = 0): Set<ID> {
let eggMovesOnly = false;
let maxGen = this.dex.gen;
const gen3HMMoves = ['cut', 'fly', 'surf', 'strength', 'flash', 'rocksmash', 'waterfall', 'dive'];
Expand All @@ -592,6 +593,9 @@ export class DexSpecies {
for (const {species, learnset} of this.getFullLearnset(id)) {
if (!eggMovesOnly) eggMovesOnly = this.eggMovesOnly(species, this.get(id));
for (const moveid in learnset) {
if (sizeLimit && movePool.size >= sizeLimit) {
return movePool;
}
if (species.isNonstandard !== 'CAP') {
if (gen4HMMoves.includes(moveid) && this.dex.gen >= 5) {
if (!learnset[moveid].some(source => parseInt(source.charAt(0)) >= 5 &&
Expand Down

0 comments on commit e2f57ef

Please sign in to comment.