I am considering using an octree to store player positions. So I would have to update the octree through RunService.Heartbeat and loop through all players.
If I am connecting to heartbeat then looping player positions to update the octree, then am I really just making performance worse unless I’m using the octree more than once per heartbeat?
For the most part, you’re not going to see benefits from an octree unless you’re using it extensively. The cost to calculate player positions is not very high, and the benefits you gain from using an octree will often be lost in construction and maintenance, especially for player positions, which change frequently.
If you already have the system built, I’d recommend doing some benchmarking to figure out how many queries per frame you’d need to make in order for the octree to beat out directly calculating distances and make an informed decision from there. If you don’t already have the system built, I’d suggest just waiting to see if distance calculations are even a bottleneck for your game before jumping through those hoops.
The main benefit of using an octree is that it lets you efficiently query spatial data, but if you’re only updating it once per frame and not using it actively for anything else during that frame, or if the amount of items are small, you might not be getting the performance boost you’re hoping for. If you’re querying the octree multiple times per frame, then updating it every heartbeat would make more sense. Otherwise direct distance checks would probably be more efficient.