mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-05-22 15:30:29 -05:00
Battle#getRelevantEffectsInner performs a lookup for the base species of
every Pokemon with ModdedDex#getEffect, then invokes callbacks. The
lookup is expensive, and callbacks very rare. In fact, there are only
ever two callbacks: one for Arceus (SwitchIn) and one for Silvally
(SwitchIn).
Instead of an expensive ModdedDex#getEffect lookup for the callbacks,
put the callbacks directly on the Pokemon's Template object.
On my machine, this commit speeds up Pokemon Showdown's tests by 20%.
Methodology: With and without this commit, I ran mocha four times with
zsh' 'time' builtin, dropped the first result, and averaged the wall
times:
mocha times before this commit:
18.20s user 0.33s system 118% cpu 15.704 total
17.91s user 0.34s system 118% cpu 15.454 total
18.11s user 0.33s system 118% cpu 15.558 total
mocha times after this commit:
15.58s user 0.33s system 122% cpu 13.028 total
15.32s user 0.33s system 121% cpu 12.890 total
15.56s user 0.32s system 121% cpu 13.068 total
Hardware:
Mid 2012 MacBook Pro
2.6 GHz Intel Core i7
Software:
Node v9.0.0
macOS 10.10.5
|
||
|---|---|---|
| .. | ||
| application | ||
| chat-plugins | ||
| simulator | ||
| .eslintrc | ||
| assert.js | ||
| common.js | ||
| main.js | ||
| mocha.opts | ||