ID:151463
 
I'm curious about the performance differences between these two scenarios.

1 map with 40 npc's moving around

vs

40 maps where 1 npc is on each map

NPC's are moving on a tick system.

I'm interested in performance concerns with having 40 maps running simultaneously on 1 server as well.

Players will only see a handful of maps at any given time. let's say 5 is the max.

Are there any other questions I should be asking?
ts
I would imagine your first scenario would run better, simply because in both instances you have the same amount of NPCs moving around, with less areas to download for the client.

However, to be more efficient, you should have the NPCs react and move around only when necessary - when say a player comes into view of them.
Tsfreaks wrote:
Are there any other questions I should be asking?

"Why am I doing premature optimization?"
In response to Alathon
Alathon wrote:
"Why am I doing premature optimization?"

I'm not sure I'd call this an optimization. This sounds more like a design decision that might have performance implications. Putting some thought towards avoiding bad decisions is different than optimization.

As for the original question about performance: I'm not sure what the answer is. It sounds like you have a specific use in mind but it's not clear what that is. Put together a test case for each method and see how they perform.
In response to Forum_account
Forum_account wrote:
This sounds more like a design decision that might have performance implications

So he's trying to figure out the most optimal way to do something, before knowing if it makes a difference. That sure sounds like premature optimization to me.

Add to that the fact that its an isolated question which is meaningless without context, and a situation that can be abstracted away so it doesn't matter either way, and it sounds even more like premature optimization to me.
In response to Alathon
Alathon wrote:
So he's trying to figure out the most optimal way to do something, before knowing if it makes a difference.

He suspects it might make a difference. If the rest of the program depends on this decision, taking time to consider what method is better is the smart thing to do.

Premature optimization is bad because it makes code messy and harder to work with. I understand how you could view this question as an optimization* but it doesn't have any of the risks that a premature optimization does. These methods are both simple and functionally equivalent, Tsfreaks is just wondering if there's a significant performance difference. Because you can never be certain of how BYOND will handle things it's very likely that two methods might seem equivalent but have drastic performance differences.

* If you think this is an optimization the act of writing code could be considered "premature optimization". Unless you're actively trying to write the most inefficient code possible you must be striving to achieve some level of efficiency. You have to think about the risks that come with an optimization. Replacing an insertion sort with a quicksort is often a no brainer - they're equivalent, quicksort tends to be more efficient, and it's a self-contained function so the change doesn't make a mess.

Edit: Reusing a variable within the same function can be bad because its name might not be appropriate for both uses and it makes the code harder to modify later. This is bad because it makes the code more confusing. The reason why you're told to avoid making optimizations like this is becauase the benefits don't outweigh the cost. You can't just look at any optimization and say "that's not a bottleneck so it's bad to make that optimization", you have to consider the consequences.
In response to Forum_account
Forum_account wrote:
You can't just look at any optimization and say "that's not a bottleneck so it's bad to make that optimization", you have to consider the consequences.

I'm not. I'm looking at his specific question and responding 'Thats premature optimization'.

You can 'wonder about design decisions' all you want, but doing so needlessly and trying to make pre-mature decisions about code structure based on insignificant benchmarks is EXACTLY what premature optimization is.

Its bad form, its a waste of time, it leads to confusing code structure that later becomes impossible to justify because it was made through baseless decisions to begin with.

So no, I don't think him wondering about this is a good thing ;) He needs to just start working on the rest of the design, and pick what feels best in context of the rest of the software.

If, later, he runs into some *staggering* difference on BYOND that makes these two different situations computationally significant (which he won't), then his code should already be structured such that its a minor change.
In response to Alathon
Alathon wrote:
Its bad form, its a waste of time, it leads to confusing code structure that later becomes impossible to justify

You're correct that premature optimization is bad because it can lead to "confusing code structure". This happens when you can choose between a clean, simple imeplemenation and an overly complex, theoretically faster implementation.

But that's not the case here. Both methods presented in [link] lead to clean, simple code. The question is: internally, does BYOND handle these methods differently enough that one method performs notably better? Because the inner workings of BYOND are quite mysterious this is a good question to ask.

I'm not sure what your "don't optimize yet" stance would mean here. [link] presents two different ways of doing something. It's not an optimized and unoptimized version, it's just two different methods.
I would argue that 40 NPCs moving around regardless of the number of z-levels is no major burden. And 40 maps doing nothing is obviously no major burden either.

As for the performance of your scenario itself, it really depends on your design. Assuming the probability of NPC collision with other objects while walking is the same either way, clearly no saving is made there. However if you choose to make NPCs on particular z-levels dormant according to where players are, then obviously some saving is had there. Although still nothing to write home about, in your example.

There is to my knowledge no inherent major performance differences in those two approaches.

As for other questions, unless you have a more realistic and complex scenario in mind (which holding out on us with that just asks for bad advice to be given, the quality of the advice is a direct product of the analysis that can be performed on YOUR problem, not the general case), I would ask myself "Why could this be a problem?".

Why do you think this could be a problem?
Within the server, the same resources will be used. Across the network, less NPCs might be in view on smaller maps, but perhaps the warping would break the environment data into larger blocks than the rows and columns of continuous movement.

If your maps are procedurally generated, then you might want to wait until you have an identifiable problem. However, cutting or merging hand-crafted maps at a later time isn't as easy. Manual creation can be a long and tedious process that you probably want to do right the first time.

I'd think you'd be happier with smaller maps even if there did turn out to be a slight performance hit. Ignore the game and worry about your own performance when creating and maintaining it. Smaller maps are more versatile and easier to edit. You can add them one at a time and they don't have to form a rectangular grid. If something goes wrong, you can cut a section out without worrying about view and movement issues. You can even change the connections between maps on a whim.
Thanks to everyone who replied. I'm just hashing out a new design spec and I felt like I was heading for trouble.

My primary concern was with the server being able to handle updating all clients simultaneously.

If you have 20 players where each had 5 open maps, that would be 100 maps needing to be constantly updated. My maps sizes are really small and there wouldn't be a whole lot going on in each. I was thinking it was similar to having 100 players logged in.

ts