• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Performance of struct

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

I noticed there is a struct in Jass gen pack 5 to support OOP, but that its implementation is actually an array underneath?

It's possible (and I've seen before) people simply use arrays with names/comments to have object like representations, but this comes a readability cost (at least for me).

Will I lose performance if I use structs?
 
no...


field is identical to i.field, no difference


struct i = 0
i.field = 5

integer i = 0
field = 5


just don't use any of the interface, stub method stuff, inheritance, or onDestroy. That stuf'll spam triggers and evaluate them.

If you really want 0 code generation from vJASS, do struct extends array, then the only code there will be your stuff.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
That depends, if you coded your stuff(spell,system,snippet,etc.) poorly then it would perform worse.

If you're talking about the allocation overhead, it does indeed require additional operations to create an instance of the struct, but is not enough to bog down your stuff.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
no...


field is identical to i.field, no difference


struct i = 0
i.field = 5

integer i = 0
field = 5


just don't use any of the interface, stub method stuff, inheritance, or onDestroy. That stuf'll spam triggers and evaluate them.

If you really want 0 code generation from vJASS, do struct extends array, then the only code there will be your stuff.



Are you saying that using interface and inheritance will reduce performance considerably? Or is this only a consideration if I'm doing real time things (timing of a spell, etc.)?
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Can you quantify how much performance? Sorry I cannot calculate this as I have no intuition on the internals behind JASS or how the structs, inheritance, etc. are implemented/translated into actual script.

Is it a small order of magnitude compared to using arrays and arbitrary conventions, like O(n) to O(log n), or exponentially slower, e.g. O(n) to O(2^n)?

Do these performance issues even matter for something like an RPG?

In my case, I am working on an RPG which involves fusing units to make new ones. The previous developer used a clever but arbitrary specification of integers to perform these mappings. This worked, but made the JASS very hard to read. I guess it is hard without a concrete example--here is one I'd like to do, which is a representation of a fusable unit:

struct monster
{
integer id
integer fusionLevel
integer family
method fuse (struct monster2) //performs the fusion
.
.
.
}

versus

integer array fusion[monster id][monster2 id]
integer array family[monster id]
integer array fusionLevels[player id][monster id]

etc...
 
You'd have to bench it and compare how long each one takes to execute. Get SharpCraft and run the benching stuff on it.

Compare a TriggerEvaluate with a function in it to a function call.

You're ok with using them, sure, they likely won't impact your map, but I'm just ballparking it here, it's likely a 1:70 ratio, 1 trigger eval = 70 function calls. Don't take me for that, I really don't remember, I just know that a trigger evaluation is much slower than calling a function.

If you're good, you can do it without inheritance/triggers.
 
Do these performance issues even matter for something like an RPG?

No. In all practical scenarios, you'll end up with similar performance (stress testing != practical). Even if you use OOP features of inheritance and polymorphism, you'll still end up with similar performance. The reason why we tend to not use them in resources is because they generate some extra code (basically, 3 or 4 handles [trigger + conditions + actions], some extra code, and a trigger evaluation to execute), but to be fair, it is very insignificant in mapping. Those handles are only generated once (3-4 handles are very cheap), and TriggerEvaluate() is fine to use as long as you don't spam it several times in a row. Unless you have the ability to detect when one thing takes X nanoseconds over another, you shouldn't notice a difference. :)
 
Status
Not open for further replies.
Top