-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data: Fix huge perf bugs in randbat tests, part 1 #10616
base: master
Are you sure you want to change the base?
Data: Fix huge perf bugs in randbat tests, part 1 #10616
Conversation
randomNPokemon
Awesome. By the way, I have been wondering whether switching |
I haven't looked too hard into the algorithms being used here. For randbats, it seems movesets are the next priority. Here's the new v8 prof for npm run full-test
I wish I could get flamegraphs working on Node but I keep getting garbage output :/. |
Previously computed whole move pool just to see whether it's empty. It accounts for about 25% of the test suite runtime.
e2f57ef
to
2843aa4
Compare
randomNPokemon
Got some more stats for
^My counters don't include calls with early returns (because those don't tend to be the expensive paths).
Context: So, the hotspots are I tried replacing |
@Slayer95 I've now read more of
Death by a thousand cuts, basically. I think the next leap in performance for It'd be nice if the test suite got faster, but that alone isn't enough motivation to do all that. I'll give it a couple more days to see if I find another freebie, but it's not looking too hopeful. On the bright side, I am seeing ~10K fewer ticks (so, ~5%) when I merge in #10608 . So, maybe we can squeeze out a few more % with just |
In a context where there are already 2 actively used competing approaches to Random Battles (Battle Factory, and "CG Teams"), I don't know how to feel about this. |
Found a less invasive and more effective way to reduce the redundant work in Total ticks went from 185K to 170K. The short-circuiting I had added for I have no strong opinions on the code style for the caches. ATM I think you could break this by changing the New v8 prof snippets
|
I estimate ~5 out of 59 seconds ( |
This is to prevent invalidating the caches derived from 'dex' at construction time
Let's Get This Merged 🚀 |
Forgot to remove this when I reverted the sizeLimit commit.
data/random-battles/gen9/teams.ts
Outdated
@@ -164,6 +164,12 @@ export class RandomTeams { | |||
*/ | |||
moveEnforcementCheckers: {[k: string]: MoveEnforcementChecker}; | |||
|
|||
/** Used by .getPools() */ | |||
private poolsCacheKey: any[] | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like this can be more specific than any[]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[string, number, boolean, RuleTable] | undefined
seems to be what it's supposed to be?
A lot of time in
npm run full-test
is spent in randbats code.Fixes
RandomTeams
etc.testSet
andtestTeam
previously constructed a generator every round, just to change the seed.getGenerator
previously called toID multiple times on the same format (least significant change)Times
added
--v8-prof
flag to mocha command forfull-test
inpackage.json
.npm run full-test
setSeed
generatortoID
format onceRandomTeams
npm run full-test
, just./test/random-battles/**/*.js
Baseline -> head: 223K -> 57K
old stats
Action:
npm run full-test
Base commit: ca27f79
Reporting granularity:
randomNPokemon: 512 calls
getMovePool: 64K calls
2,841,615+ calls to
getMovePool
came fromrandomNPokemon
.console dump for pre times
unit: milliseconds.
each row is 512 or 64K calls.
Something to check later in
randomNPokemon
:Array
.includes
called on 1000 element arrays of ints. On the order of a billion elements are visited duringnpm run full-test
. Int ops are pretty fast, so probably not an issue. But there's potential for a speed-up here.size of pool in `randomNPokemon` when calling `.includes`
length
: frequency