pokemon-showdown/server/chat-plugins
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
..
randombattles Super Staff Bros: Implement bugfixes and balance updates (#10448) 2024-08-12 23:25:34 -06:00
trivia Trivia: Fix official-ending message 2024-08-22 05:26:21 +00:00
abuse-monitor.ts Artemis: Give drivers access to /am edithistory 2024-06-18 15:56:49 -05:00
announcements.ts Announcements: Allow editing to be multiline 2024-01-29 22:13:34 -07:00
auction.ts Auctions: Remove credits column in snake draft (#10545) 2024-09-12 15:36:40 -06:00
battlesearch.ts Make the logs/ directory prefix configurable 2024-05-19 12:30:22 -05:00
calculator.ts Limit sigfigs in /math (#10244) 2024-04-11 21:54:45 -06:00
cg-teams-leveling.ts Refactor BestOfGame (#10026) 2024-01-07 01:45:23 -08:00
chat-monitor.ts Utils#Multiset: Redefine get to remove undefined return (#10329) 2024-06-06 17:16:59 -06:00
chatlog.ts Chatlog: Use Replays database for /gbc if available 2024-07-20 18:40:34 -05:00
COMMANDS.md Add a bit more documentation for plines 2021-04-28 01:53:03 -07:00
daily-spotlight.ts Spotlights: Fix "Refresh" button opening another tab (#8684) 2022-03-10 15:59:39 -08:00
datasearch.ts Datasearch: Optimize runDexsearch (#10536) 2024-09-17 11:46:35 -06:00
friends.ts Friends: Use user's local time for last seen information 2024-06-05 16:39:02 -05:00
github.ts Git reporting: Add pokemon-showdown-loginserver to reported repos 2023-03-26 14:23:55 -05:00
hangman.ts Remove unlinkUser (#10101) 2024-01-08 20:49:34 -08:00
helptickets-auto.ts Auto-helptickets: Refactor pmharassment/battleharassment reasons 2022-02-28 15:03:21 -06:00
helptickets.ts Helptickets: Prevent unregistered users from submitting IP-Appeals 2024-09-12 21:40:33 -05:00
hosts.ts Fix addhosts grammar 2023-01-14 14:22:17 -06:00
mafia.ts Mafia: Show eliminated players in order of elimination 2024-08-02 22:24:11 -04:00
modlog-viewer.ts Utils#Multiset: Redefine get to remove undefined return (#10329) 2024-06-06 17:16:59 -06:00
othermetas.ts Add August 2024 rotational formats 2024-08-01 01:30:27 -06:00
permalocks.ts Permalocks: Ensure icons are saved 2023-09-17 22:49:10 -05:00
poll.ts Polls: Allow escaping separators (#9074) 2022-12-09 17:49:47 -08:00
quotes.ts Add support to /removequote last (#10472) 2024-08-06 00:42:50 -05:00
repeats.ts Extend /repeat multiline pattern for all commands (#8593) 2021-12-29 21:18:57 -08:00
responder.ts Make the logs/ directory prefix configurable 2024-05-19 12:30:22 -05:00
room-events.ts Roomevents: Check /roomevents add permissions for viewing source 2021-05-20 09:36:11 -05:00
room-faqs.ts Improvements to room FAQs and repeats (#9270) 2023-10-22 18:28:33 -05:00
sample-teams.ts Deprecate Sample Teams 2024-02-14 11:59:32 -07:00
scavenger-games.ts Scavengers: Support HTML in hunts (#10414) 2024-08-21 18:51:02 -05:00
scavengers.ts Scavs: Fix crash 2024-08-29 16:12:03 -05:00
seasons.ts Fix typo 2024-08-21 22:42:24 -05:00
smogtours.ts Smogtours: Require accredation on images 2023-09-18 22:58:37 -05:00
suspect-tests.ts COIL: Fix help text (#10480) 2024-08-08 00:05:21 -06:00
teams.ts Teams: Ensure empty teams cannot be uploaded at any stage 2024-06-05 09:28:22 -05:00
the-studio.ts Update various instances of old author names 2024-07-01 12:23:44 -06:00
thing-of-the-day.ts Update /otd help (#9900) 2023-11-13 15:45:39 -06:00
uno.ts Cleanup RoomGame implementations again 2024-01-16 15:54:38 +09:00
username-prefixes.ts Prefix-Manager: Update help 2022-11-06 13:17:30 -06:00
usersearch.tsx Usersearch: Convert to TSX (#8641) 2022-02-15 17:19:17 -08:00
wifi.tsx Appease linter 2024-07-01 13:13:59 -06:00
youtube.ts /show: Remove extraneous button while broadcasting 2024-08-31 13:59:23 -05:00