Looking for Tips to Optimize Client-Sided Stress

Hello there,

I am currently developing a game which involves the constant dropping of hundreds of snowballs, spheres, on each individual client at once. I have found issues in regards to optimization, as obviously having this many unanchored parts can cause many issues like that. Currently I have a system which anchors every snowball after a few seconds, once it has rolled to the bottom of the collection area, to prevent lag. However, this doesn’t seem to help with everything. If you need more information, please let me know! Any help would be appreciated.

Just to be clear, the snowball spawning is unique to every client, and does not happen on the server. (In attempt to control server-sided stress.)

Thank you!

2 Likes

what is the memory usage for the game currently?

Are you sure the lag is mostly due to physics?

It might also be due to creating the instances, do you use a module like Partcache?

Otherwise perhaps this post should help, are the snowballs baseparts or meshparts? Collision geometry may make things worse as the post below suggests:

Thank you for your replies.

I am using regular Parts, just simply with sphere shapes.
Currently, I am just creating the instances with the built in Instance.new() function, which I suppose is probably pretty unoptimized in itself. What method would you say would be better?

1 Like

whats the memory usage at? there might be a memory leak or something

Definitely use PartCache then.

If you’re unfamiliar, here’s what I would do with it:
When the client joins, create a cache with a couple hundred snowballs. Whenever you need to spawn one, take one from the cache, position it where you need it to be and unanchor. When you want to remove it, return it to the cache and anchor.

Mind providing a bit of a code sample in regards to its use? I am unfamiliar with the module.

local PartCache=Instance.new("Folder",game.ServerStorage)
PartCache.Name="PartCache"
local Part = Instance.new("Part",workspace)
Part.Name="snowball"
Part.Anchored=false
task.wait(5)
Part.Anchored=true
Part.Parent=PartCache

example script lets say your script uses that snowball for 5 seconds and now it doesnt need to use that snowball anymore so instead of calling :Destroy I will put it back into PartCache and anchor it

PS this example will work only on server script if you want to use it inside localscript i would parent the folder to ReplicatedStorage

Sure, PartCache is a very simple and lightweight module. Here’s the link:

-- When the client joins, call this function and keep snowballCache 
-- in a ModuleScript if multiple client scripts need to access it
local snowballCache = PartCache.new(snowball, 500) -- Change the number to however many you need

-- If you want to store your snowballs in a folder or some other container, use SetParent
snowballCache:SetParent(workspace.Snowballs) 

-- To spawn a snowball:
local snowball = snowballCache:GetPart()
snowball.Position = position
snowball.Anchored = false

-- To remove a snowball:
snowballCache:ReturnPart(snowball)

The most optimal approach would be to spawn them all on the server and let the server manage distributing that work among clients, which it will do automatically.

What issues were you seeing when trying this?

1 Like