Necessary or Unnecessary? Code Optimization

To get straight to the point, is it worth it?

Most people would do things such as

Delete Everything
Reload Everything

So is it worth it?

Let me further explain; let’s say I was making an inventory system, I wanted to refresh my inventory knowing what is deleted and what needs to be created visually. Would it be worth it to loop through everything on the client, compare it to the server, see what’s missing and then loop through the server, compare with the client and see what no longer exists?

It’s a lot of work to check, a simpler example is custom player leader board, where players leave and join and you’d need to update.

So:

For inventory systems should I just delete everything and then reload everything?
For Custom Player Lists should I delete everything and then reload everything?
For Client Sided Effects is it worth looping through all the players, checking who is nearby and relevant, and then firing to those specific clients?

EDIT: This is in terms of code optimization

For the first two problems, why reload everything, when you can simply reload the wanted tool, or remove the wanted player. Try your best to do less things.

I actually delt with someone that had your problem an hour ago

You can see, he had vague fps problems, because he was constanly reloading everything. A simple fix, was to just reload when needed, and only reload the wanted thing.

For the third problem, can you explain more please? Why would you want to only effect the nearest player?

1 Like

I would like to affect the nearest character because others won’t even be able to see it at far distance. So I was wondering if I should :FireAllClients or loop and see who’s relevant.

As for the first 2, for some reason, sometimes an item stays or doesn’t get added. Right now my solution is to loop through everything, compare and make changes.

Good idea, checking for the nearest players and just sending the effects for them, which is also not costly. The thing is, even if you’re gonna show it for a few people, you’re still gonna be sending info to the server
Client → Server → Nearest clients, so it’s the same process effort for the server, with some additional tasks of searching for nearest players, but the benefists of this decreasing the lag for certain clients, which is good.

For the first 2, there might be a reason the change isn’t applying for just one thing, try to fix it instead of doing it on everything

1 Like