Author Topic: No fix for ghost collisions with planet eaters necissary  (Read 1542 times)

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4481
    • View Profile
    • DJ Paul Kononov
Re: No fix for ghost collisions with planet eaters necissary
« Reply #15 on: January 26, 2014, 11:04:10 AM »
Just ran sleepy again with your method:

That eyestrength thing is indeed eating up a lot. Numsgil, here is the code for eyestrength, any idea how to make it faster? It is supposed to trow a Boolean and revert to 1.

Code: [Select]
0.25s Private Function eyestrength(n1 As Integer) As Single 'Botsareus 2/3/2013 eye strength mod
Const EyeEffectiveness As Byte = 3  'Botsareus 3/26/2013 For eye strength formula

If SimOpts.Pondmode And rob(n1).pos.y > 1 Then 'Botsareus 3/26/2013 Bug fix if robot Y pos is almost zero
  eyestrength = (EyeEffectiveness / (rob(n1).pos.y / 2000) ^ SimOpts.Gradient) ^ (6828 / SimOpts.FieldHeight)  'Botsareus 3/26/2013 Robots only effected by density, not light intensity
Else
0.02s   eyestrength = 1
End If


0.02s If Not SimOpts.Daytime Then eyestrength = eyestrength * 0.8

0.03s If eyestrength > 1 Then eyestrength = 1

End Function

This is called from all over the place in the buckets module such as:

Code: [Select]
'Returns the distance an eye of absolute width w can see.
'Eye sight distance S varies as a function of eye width according to:  S =  1 - ln(w)/4
'where w is the absolute eyewidth as a multiple of the standard Pi/18 eyewidths
Public Function EyeSightDistance(w As Integer, n1 As Integer) As Single 'Botsareus 2/3/2013 modified to except robot id
  If w = 35 Then
    EyeSightDistance = 1440 * eyestrength(n1)
  Else
    EyeSightDistance = 1440 * (1 - (Log(w / 35) / 4)) * eyestrength(n1)
  End If
End Function

Good find btw.

Online Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7689
    • View Profile
Re: No fix for ghost collisions with planet eaters necissary
« Reply #16 on: January 26, 2014, 01:39:17 PM »
It looks like most of the expense is the overhead of calling a function.  What does the callstack look like?

Basically, you should probably only ever need to call this once per bot per cycle.  If it's getting called more than that, that would be the issue.  You want to cache the values you get for each bot instead of recalculating them.

This is one of those cases where there's not much you can do to speed up the function itself, so you have to figure out ways to call it less frequently.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4481
    • View Profile
    • DJ Paul Kononov
Re: No fix for ghost collisions with planet eaters necissary
« Reply #17 on: January 26, 2014, 06:30:06 PM »
Ok, I'll play with it, see what I can come up with. It does not look too promising though. If I get a reasonable speed improvement expect a revision drop soon.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4481
    • View Profile
    • DJ Paul Kononov
Re: No fix for ghost collisions with planet eaters necissary
« Reply #18 on: January 28, 2014, 10:44:58 AM »
Nah, did not help a bit, My speed is exactly the same if I declare eyestrength in robot structure (and stuff) or I do not.
« Last Edit: January 28, 2014, 11:02:43 AM by Botsareus »

Online Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7689
    • View Profile
Re: No fix for ghost collisions with planet eaters necissary
« Reply #19 on: January 28, 2014, 11:27:24 AM »
That must not have been the bottleneck then :/

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4481
    • View Profile
    • DJ Paul Kononov
Re: No fix for ghost collisions with planet eaters necissary
« Reply #20 on: January 28, 2014, 11:42:24 AM »
It is not that bad Numsgil, I think we can live with 20% slower code... I am thinking it is the combination of all the new mods together, and there is no specific bottleneck... Thanks for your help, at least I learned proper bottleneck finding skills using a profiler from this experiment.

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Re: No fix for ghost collisions with planet eaters necissary
« Reply #21 on: January 28, 2014, 05:32:23 PM »
No specific bottleneck is weird. Uniform slow code is rare.
Oh my god, who the hell cares.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4481
    • View Profile
    • DJ Paul Kononov
Re: No fix for ghost collisions with planet eaters necissary
« Reply #22 on: January 29, 2014, 02:04:59 PM »
I can not find anything. Trust me, I looked. All the functions I looked at are taking as much % as I expect them to take. Also, I can not find any that I can optimize to be faster.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4481
    • View Profile
    • DJ Paul Kononov
Re: No fix for ghost collisions with planet eaters necissary
« Reply #23 on: February 11, 2014, 11:43:58 AM »
Numsgil, I found something very interesting. Apparently "readtie" was excepting the counter from UpdateBots byref and then changing it. Causing the loop to repeat or even hang with half the loop never being executed. Very ugly. Fixed. I hope this one improves speed.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4481
    • View Profile
    • DJ Paul Kononov
Re: No fix for ghost collisions with planet eaters necissary
« Reply #24 on: February 14, 2014, 03:31:55 PM »
Wow, I put byvals everywhere it was safe to do and the program is flying now.