littensy / slither

🐍 A casual game with a soothing Catppuccin color palette
https://www.roblox.com/games/14162747150
MIT License
119 stars 9 forks source link

General server optimizations #27

Closed littensy closed 1 year ago

littensy commented 1 year ago

Using the script profiler after spawning several bots with a score of 10,000, I can see potential areas to optimize code. This issue may be edited in the future to include more potential optimizations.

Candy

Candy selector

Line 40 of the candy-selectors script seems to point to an expensive selector. Pinpoint code using this selector and opt for a cheaper selector.

image

Candy state

Updating the candy state when a player eats candy seems to be more expensive than it has to be. It may be optimized by batching setCandyEatenAt dispatches to update it all at once rather than be dispatched per candy.

This time may also be taken up by an unnecessarily expensive computation somewhere that dispatches this too many times.

Another optimization for this and other similar actions may be to replace mapObject with a new function, mapObjectProperty, that instead replaces a value in the state with a new value.

image
littensy commented 1 year ago

After further investigation, this does not cause performance issues on its own. However, the death of a large snake and its candy still drops frames, and will need to be optimized. The other optimizations outlined in this issue would also be nice.

littensy commented 1 year ago

These optimizations were applied in #34 when refactoring the snake and candy slices.