Pokémon battle simulator.
Go to file
larry-the-table-guy ddf5848a38
Datasearch: Optimize runDexsearch (#10536)
* add crude profiling to runDexSearch

No behavioral changes (other than console.log spam), this commit is just to establish a baseline and pinpoint the slow portions

* optimize datasearch.ts - pull move filter prep out of loop

Based on preliminary benchmarks, most of the time was spent getting the move validator, even for queries that don't specify a move.
More importantly, the parameters for fetching the move validator are known very early in the function and don't change during the loop.
Pulling that portion out of the loop is an easy win.

* improve profiling for runDexSearch

- add subcategories for filtering on move (the next optimization target)
- report unaccounted time amounts ('known unknowns')
- make grand total stand out more

* optimize dexsearch - fetch move list in outer loop

Move list depends on 'alts', which does not change in the loop over mons. Minor win, but simple.

* optimize dexsearch - filter move list by gen in outer loop

Neither 'mod' nor 'altMoves' changes during the inner loop.

* log pokemonSource in runDexSearch - expose possible leak

pokemonSources, which appears to act as a set, grows with each iteration, adding seemingly redundant items.
Will need to look closely at TeamValidator to identify the problem. My guess is that it's putting object references into a Set,
which, for objects other than strings, only cares about object identity.

* profile runDexSearch - count checkCanLearn calls

Also, semi-fix issue identified in prior commit - the endless growth of the restrictiveMoves list.
Counting the calls to checkCanLearn helps us reason about whether the cost per call is reasonable.

* fix perf bug in TeamValidator.checkCanLearn

use the cached ruleTable, save 100x.

* optimize runDexSearch - only init move filters when needed

For queries that never mention a move, a considerable chunk of time is wasted getting the objects needed for
'checkCanLearn'. I measure ~1ms savings for the relevant queries, which is often a decent percentage.

* profile dexsearch - delete and format

This is to document that they are not the bottlenecks.

* remove nested profiling from dexsearch

We've gotten to the point where we actually *are* measuring microseconds, so the frequent calls
are too expensive. This is a good problem to have! What we can see from running npm test is
that 'filters' and 'unaccounted' still account for a majority of the time. So, there's still
room for improvement, if that's ever a serious concern.
Personally, I think working on the moves API would be more fruitful.

* remove all profiling code

No more console.log or performance.now() calls. Ready to merge.

* Update server/chat-plugins/datasearch.ts

Format the 'format' string in-line.

Co-authored-by: Mia <49593536+mia-pi-git@users.noreply.github.com>

* Remove ts-expect-error from datasearch.ts

* Fix uninit lint in runDexSearch

---------

Co-authored-by: Mia <49593536+mia-pi-git@users.noreply.github.com>
2024-09-17 11:46:35 -06:00
.github/workflows CI: Force pull requests to fetch history (#9720) 2023-09-24 19:29:51 -07:00
.vscode Turn off Format on Save in VS Code (#7807) 2020-12-24 09:44:24 -08:00
config Triples: Ban Indeedee (#10555) 2024-09-17 10:32:14 -06:00
data Randomized format set updates (#10552) 2024-09-17 10:34:07 -06:00
databases Roomlogs: Support logging to Cockroach instead of flat files (#10298) 2024-05-15 16:12:07 -05:00
lib Utils#Multiset: Redefine get to remove undefined return (#10329) 2024-06-06 17:16:59 -06:00
logs Restore READMEs for logs/ subdirs 2021-10-06 16:55:39 -05:00
server Datasearch: Optimize runDexsearch (#10536) 2024-09-17 11:46:35 -06:00
sim Datasearch: Optimize runDexsearch (#10536) 2024-09-17 11:46:35 -06:00
test Randomized format set updates (#10552) 2024-09-17 10:34:07 -06:00
tools Fix tools/set-import/index.js (#9865) 2023-10-30 12:59:33 -05:00
translations French: Fix Bot description in /group (#10304) 2024-05-17 18:30:51 -07:00
.editorconfig
.eslintrc-no-types.json Migrate to esbuild for compilation (#9203) 2022-12-22 15:19:29 -06:00
.eslintrc.json Fix ESLint errors 2022-02-14 20:42:09 -08:00
.gitattributes
.gitignore Fully gitignore logs/ 2024-05-18 03:27:11 -05:00
.mocharc.json Random Battles: Add basic unit test framework 2021-03-18 18:17:25 -07:00
.npmignore Include config-example.js in npm package 2023-04-14 03:47:01 +09:00
.npmrc Add package-lock.json 2023-02-16 19:42:58 -05:00
ARCHITECTURE.md Fix dead links in docs (#10097) 2024-01-10 05:50:18 -08:00
build Don't rebuild if installed by NPM package 2023-04-14 11:44:52 +09:00
CODEOWNERS Add Super Staff Bros: Ultimate (#10279) 2024-05-04 12:01:51 -06:00
COMMANDLINE.md fix sim/README.md hyperlink (#9896) 2023-11-12 22:49:50 -06:00
CONTRIBUTING.md Explain how to access localhost.psim.us 2022-11-10 18:25:53 -08:00
LICENSE Update LICENSE year (#10216) 2024-03-19 23:59:10 -04:00
old-simulator-doc.txt
package-lock.json Bump mysql2 version 2024-04-24 00:41:15 -05:00
package.json Bump mysql2 version 2024-04-24 00:41:15 -05:00
pokemon-showdown Use source maps in pokemon-showdown validate-team 2023-12-08 23:29:54 -05:00
Procfile
PROTOCOL.md PROTOCOL.md: New API! New API! 2023-03-26 15:26:18 -07:00
README.md Update various instances of old author names 2024-07-01 12:23:44 -06:00
simulator-doc.txt Fix bugs with secondary/ability order 2020-02-08 08:07:39 -08:00
tsconfig.json Move Random Battles files to a separate folder (#10285) 2024-05-09 18:52:33 -06:00

Pokémon Showdown

Navigation: Website | Server repository | Client repository | Dex repository

Build Status Dependency Status

Introduction

Pokémon Showdown is many things:

Pokémon Showdown simulates singles, doubles and triples battles in all the games out so far (Generations 1 through 9).

  • PROTOCOL.md - How the client and server communicate with each other.

  • sim/SIM-PROTOCOL.md - The part of the protocol used for battles and battle messages.

  • CONTRIBUTING.md - Useful code standards to understand if you want to send pull requests to PS (not necessary if you're just using the code and not planning to contribute back).

  • ARCHITECTURE.md - A high-level overview of how the code works.

  • Bot FAQ - An FAQ compiled by Kaiepi regarding making Pokemon Showdown bots - mainly chatbots and battle bots.

Community

PS has a built-in chat service. Join our main server to talk to us!

You can also visit the Pokémon Showdown forums for discussion and help.

If you'd like to contribute to programming and don't know where to start, feel free to check out Ideas for New Developers.

License

Pokémon Showdown's server is distributed under the terms of the MIT License.

Credits

Owner

  • Guangcong Luo [Zarel] - Development, Design, Sysadmin

Staff

  • Andrew Werner [HoeenHero] - Development
  • Annika L. [Annika] - Development
  • Chris Monsanto [chaos] - Development, Sysadmin
  • Kris Johnson [dhelmise] - Development
  • Leonard Craft III [DaWoblefet] - Research (game mechanics)
  • Mathieu Dias-Martins [Marty-D] - Research (game mechanics), Development
  • Mia A [Mia] - Development

Contributors