Author Topic: Technical Question - GetObjectByTag or...  (Read 2202 times)

Legacy_OldTimeRadio

  • Hero Member
  • *****
  • Posts: 2307
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #45 on: August 23, 2011, 05:35:37 am »


               Great work, everyone!  And hella useful stuff to know.  One error, which I am guilty of, is using Google (or the NWN Omnibus) to search the old BioWare forums for answers and then giving those answers a little too much weight- usually because it's a PITA to test (whatever).  This problem gets compounded when you think that the test results you might find are, say, from 2004 and on a much earlier build of NWN. 

Getting fresh tests like this against 1.69 is solid gold, IMO.
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #46 on: August 23, 2011, 05:27:07 pm »


               <looking all around...>

How does GetFirstObjectInShape compare for finding near-by things? Is that looking through the whole list also?

Very interesting thread :-) I dig this stuff.

<...at the *Big* dogs>
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #47 on: August 23, 2011, 06:12:49 pm »


               I'll be running more tests. It seems likely that the second function call (GetModule()) is responsible for the doubled time of GLO vs GObT - function calls have non-negligible overhead. Might ask Skywing for an OBJECT_MODULE const as a result (GetModule() almost alawys returns object 0, according to acaos - the only case in which it doesn't is if you use StartNewModule()) . Will be caching the waypoint and module in vars in order to isolate function runtimes, and comparing GetWaypointByTag to GObT on waypoints to see a) whether GObT's optimization might actually make it better (unlikely), and 'B)' whether I can stop worrying about our mod's waypoint count (likely, if GWbT has similar optimization to GObT's).

As for GetFirstObjectInShape, I can't imagine it'd be better than Nearest - if you needed to find the nearest - since you'd wind up measuring distance manually. Those you would just use as-needed. Bear in mind that this is all sort of wonky in terms of impact - using one of these functions versus another is unlikely to have a noticeable impact on your server. It's more of a fetish, really, though those of us who indulge it like to tell ourselves that our servers run marginally more smoothly as a result. You need huge numbers of repetitions in order to see significant runtimes on these methods. In the case of GObT, it's particularly noteworthy, because many of us were going to pains to avoid using it - it's both more convenient and more efficient than getting Nearest to a Waypoint.

Funky
               
               

               


                     Modifié par FunkySwerve, 23 août 2011 - 05:16 .
                     
                  


            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #48 on: August 23, 2011, 06:20:26 pm »


               <ears ring...>

I asked that because I ran across some default functions somewhere in the AI that was using GetFirst/NextObjectInShape... I'll try and remember where I saw it, but that seems a viable target for re-scripting - if it hasn't been already.

With the amount of background stuff I (eventually) want to have going, *every* bit helps. Or, um, lack of bit, I suppose... =)

<...he's listening so hard>
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #49 on: August 27, 2011, 03:08:25 am »


               Ran some more tests. I modified the old scripts to cache the GetModule() and GetWaypointByTag() calls on variables, so that the functions were only called once, in an effort to pinpoint exact costs. Here are the scripts for this run:

test_gobt (unchanged)

void main()
{
    object oDiseaseControl;
    int nX;
    for (nX = 0; nX < 1000; nX++)
        oDiseaseControl = GetObjectByTag("disease_vuln");
}

test_gnobt

void main()
{
    object oDiseaseControl, oWay = GetWaypointByTag("effectsareawaypo");
    int nX;
    for (nX = 0; nX < 1000; nX++)
        oDiseaseControl = GetNearestObjectByTag("disease_vuln", oWay);
}

test_glo

void main()
{
    object oDiseaseControl, oMod = GetModule();
    int nX;
    for (nX = 0; nX < 1000; nX++)
        oDiseaseControl = GetLocalObject(oMod,"disease_vuln");//set on modload
}

Run results:

test_gnobt 314 runs 3333 total time
test_gobt 314 644
test_glo 314 1216

Clearly overhead from functions had little to do with it. GNObT is only about 5 times as slow, as opposed to 9, when you don't have to get the waypoint - not that such a situation comes up in practice. GLO is still about twice as slow, meaning that GetModule() is very fast, as expected. I didn't clock GWbT against GObT, but plan to.

Funky
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #50 on: January 08, 2012, 06:10:06 pm »


               So... has anyone clocked GetWaypointByTag?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #51 on: January 08, 2012, 11:06:46 pm »


               The only thing that I know of being done is the test that funky already did and posted on.  More of just a compairsion test then anything?
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #52 on: January 08, 2012, 11:18:04 pm »


               Funky did a test of GetWaypointByTag versus GetObjectByTag?

All I saw was that he planned to do one at some point, but I don't see the results of the test anywhere.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #53 on: January 08, 2012, 11:25:48 pm »


               logically GetWaypoint should be faster, but who knows?

And I wouldnt be very trustful to the "clocking results", one day its this and the other day that.

For example in past someone (not sure who unfortunately) clocked OBJECT_SELF, and said that while its indeed macro and not constant its faster than being assigned into variable before.

Year ago, The Krit claims otherwise. Not sure where he get this, in nwn wiki there is no proof for this, but you can see my point.
               
               

               


                     Modifié par ShaDoOoW, 08 janvier 2012 - 11:55 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #54 on: January 08, 2012, 11:36:09 pm »


               Funcky did his test in this post. Stating that "I may not have to do any others."

My opinion on the OBJECT_SELF question.   is that OBJECT_SELF should be faster.  I am not sure where the macro comes into play.    macro's are more of a compile time function on how the script is coded then code that runs after then script is built.     There should be such a small differance between OBJECT_SELF and a var though to make it moot point.    
  
               
               

               


                     Modifié par Lightfoot8, 08 janvier 2012 - 11:47 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #55 on: January 08, 2012, 11:50:25 pm »


               As far as I can see, he did not post any results for GetWaypointByTag there. That post was about quantifying the difference between GetObject and GetNearestObject
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #56 on: January 09, 2012, 01:41:57 am »


               

henesua wrote...

As far as I can see, he did not post any results for GetWaypointByTag there. That post was about quantifying the difference between GetObject and GetNearestObject



Ok, I did not understand.   The test is best done in a large server,  I currently have 5 people on the server I am running so I can not do the test right now.    I woll run a profile when I get a chance with no one on the server.  i can see no reason why thr result would be any different from GetObject though.     So i am thinking of a test between,   GetObjectByTag  and GetWayPointByTag.    Both functions just returning a unique object per the tag.  are there other functions that you would added to the profile?
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #57 on: January 09, 2012, 02:04:33 am »


               Well to establish a control (point of comparison with what Funky did) also run GetNearestObjectByTag. That should round this out.

Congrats on the five players. I'm currently only averaging 2 players. Only had as much as five players for an hour last night.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #58 on: January 09, 2012, 04:22:12 am »


               Ok I hae results,   Basicly I set it up to where one script called the three other scripts 1000 times.   each of the three scripts found the object 50 times and assigned the value to a var.   The module has umm I want to say about 600 areas in it.  I am not even going to guess at how many waypoints there are.

results.

Script______Runs___Time

test_profile....26........... 6609
test_gobt ......26000.....27448
test_gnobt.....26000.....48438
test_gwbt.......26000.....29288

EDIT:  one flaw I can see in my test is that I used a tag that started with an 'a'  So i am rerunning the test with a tag with a 'Zep_ Prefix.   will report back.
               
               

               


                     Modifié par Lightfoot8, 09 janvier 2012 - 04:28 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Technical Question - GetObjectByTag or...
« Reply #59 on: January 09, 2012, 04:42:04 am »


               ok, second test with the "Zep_**" tag same results.

Script______Runs___Time
test_profile.....31.............8204
test_gobt........31000......18216
test_gnobt......31000......65103
test_gwbt.......31000.......19318


I am assuning that the GOBT is out performing GWBT because both functions are seraching the same internal list.  GWBT has a little extra overhead having to check the object type to see if it is a waypoint.
 
EdiT:  I forgot to say thanks on the congrats for the number of players,  It is a rear event to see that many though,  Normally it is just a barren world.   It is normally just old players comming around to reminisce and shoot the breeze.
               
               

               


                     Modifié par Lightfoot8, 09 janvier 2012 - 04:54 .