ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Script optimization question

« Previous 10 events | 1 2 3 4 | All Messages
Posted by/on
Question/AnswerMake Oldest Up Sort by Ascending
  00:08:09  29 January 2013
profilee-mailreply Message URLTo the Top
SetaKat
Ex modder, Zones only ferret and will someday release a game
(Resident)

 

 
On forum: 02/20/2010
Messages: 6340
Thanks for that info on 'and' operators being slow, will remove them from my own scripts now, should get a speed boost.
  23:05:12  28 January 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685
I would say version A2 is fastest.

Why?
Local variable declarations are faster than global declarations. Which means local declaration outside a function block are not belonging to a function in first place. Those variables need to be indexed.
Declarations within a function block are directly belonging to that function block. No need to index them.
To call an indexed variable causes to search thru the index, which takes time. To call a variable directly causes no time.

'AND' operations are quite slow, so it's better to two 'if'-conditions in two lines rather than in in one line linked with 'AND'.

Hope you understand what I mean.
  22:46:56  28 January 2013
profilee-mailreply Message URLTo the Top
Decane
Senior Resident
 

 
On forum: 04/04/2007
 

Message edited by:
Decane
01/28/2013 22:57:38
Messages: 1703
Script optimization question

Of the following codes, which is fastest and why?

(A1)

local act = db.actor
function test()
  if not has_alife_info("tester") then
    if IsStalker(act) then
      act:give_info_portion("tester")
    end
  end
end


(A2)

function test()
  local act = db.actor
  if not has_alife_info("tester") then
    if IsStalker(act) then
      act:give_info_portion("tester")
    end
  end
end


(B1)

local act = db.actor
function test()
  if not has_alife_info("tester") and IsStalker(act) then
    act:give_info_portion("tester")
  end
end


(B2)

function test()
  local act = db.actor
  if not has_alife_info("tester") and IsStalker(act) then
    act:give_info_portion("tester")
  end
end


Apart from remarks relating to the stuff above, other optimization tips are also welcome.

EDIT: Also, which of these is faster?

if db.actor then
...


if db.actor ~= nil then
..


Or are they equally fast?

All this is strictly theoretical speed, by the way; I know that in practice the difference will be negligible.
 
Each word should be at least 3 characters long.
Search:    
Search conditions:    - spaces as AND    - spaces as OR   
 
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
 

All short dates are in Month-Day-Year format.


 

Copyright © 1995-2020 GSC Game World. All rights reserved.
This site is best viewed in Internet Explorer 4.xx and up and Javascript enabled. Webmaster.
Opera Software products are not supported.
If any problem concerning the site functioning under Opera Software appears apply
to Opera Software technical support service.