What's the performance impact of :MoveTo() and similar methods? (Humanoid)

I’m working on NPCs and looking for ways to optimize them, I already know that pathfinding is expensive to compute so I have a couple of ideas on how to minimize the resources spent on that, but does :MoveTo() need the same caution?

unlike :Move(), according to the roblox docs :MoveTo() attempts to reach the destination, it also has a timeout of 8 seconds, and I’m pretty sure it also checks if the character is stuck before dropping it so I assume that it’s more performance heavy than just using :Move()

does anyone know what performance effects do these methods have? it may be fine on a couple of NPCs, but I wanna know if it still holds up on dozens of NPCs moving simultaneously

1 Like

From experience, I would say yes and impact is marginal. Im working on an open world project with almost 200npcs rendered at times, all using MoveTo. I haven’t ran into any noticeable issues. That said, I also havn’t benchmarked or clocked the operation ever compared to anything else.

2 Likes

MoveTo itself isnt really much heavier than Move, while ofc it is a bit less performant, its basically just Move with a distance checks and a simple correction logic, nothing really to worry about. Especially considering humanoid built-in functions are written in c, it will always be more performant than any custom luau equivalents (unless you manage to simplify it for a special purpose case).

To be completely honest, humanoids are just baseline extremely heavy, and you can only optimize them so much. Even with pathfinding, the humanoids will 99% of the time be more costly than anything you use them for. As @mc3334 already mentioned though, you should be able to run a several dozen of them without any problems, as I can also personally vouch that using over a 100 of them is still pretty solid. If you’d like to go above that however, the best thing you can do is to look into either a way to reduce the required amount of active humanoids at one time (like clearing ones currently inactive, even if for a while). Or make custom ones with just the features you need for your purposes. Humanoids have to be written so they work in almost every case you might need em for, most of the time packing features you will never realistically need, so they will hardly ever match a specialized equivalent with just the features required for their purpose.

3 Likes

I mean :MoveTo() by itself isn’t an expensive function, it’s the code that moves the humanoid towards :MoveTo() (which I assume is updated every frame, possibly .PreSimulation?) that costs performance. But besides that, it’s also humanoid states that cause a lot of lag because they have to be updated very frequently to even be reliable to connect to.

This is why some folks recommend disabling humanoid states to reduce humanoid lag. If you want a lot of humanoids, you’re going to probably want to look into developing your own custom humanoid system (I give one example down below).

Big side note though!

This will be fixed in a couple of weeks, but there is a known bug where disabling Enum.HumanoidStateType.FallingDown would trigger raycast calls that would horribly lag your game.

Beyond the computational stress on the server, you also face issues of network bandwidth with your clients. From my personal testing:

  • 5 humanoids ------> ~4 KB/s
  • 25 humanoids ------> ~17 KB/s
  • 75 humanoids ------> ~40 KB/s
  • 200 humanoids ------> ~110 KB/s
  • 500 humanoids ------> ~160 KB/s

Keep in mind that Roblox puts a softlimit of 50 KB/s on network bandwidth (you can view this with PerformanceStats). If you go beyond this limit, the game will attempt to throttle the network back into 50 KB/s which leads to a lot of laggy humanoids on the client’s side.

If you want to use a lot of humanoids, I suggest considering custom NPC replication. The basic logic for this is:

  • Pathfind + send position data for NPCs on server (rather than placing actual models and humanoids and letting Roblox handle the replication)
  • Render position data for NPCs on client

If you’re interested in this, read this post by @Atrazine which may give you a hint as to how to make this system. If you want to read more on optimization tricks for this kind of system (can be used in general as well), you can read this post I wrote.

3 Likes

This is what I do by the way, night and day difference. Highly recommend leaving all humanoid related stuff to the clients, theyre bandwith eaters.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.