forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sometimes it's nice to be wrong (Lua performance)

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
Durante



Joined: 02 Oct 2005
Posts: 65
Location: Austria

PostPosted: Mon Oct 24, 2005 1:32 am    Post subject: Sometimes it's nice to be wrong (Lua performance) Reply with quote

I was pretty disappointed just now that -- after finally implementing one of the more complex things about my game correctly -- Lua seemed to be far slower than I expected, even though I included many early exits, etc.

Well, I tried various possibilities of speeding things up, but none helped much. I already contemplated the horrifying possibility of implementing my game in C when I finally saw the impact of line [1].

Code:

   Circle:eachLine(function(p1, p2)
      -- do nothing for current line
      if not (p1 == self.cur_point or p2 == self.cur_point) then
         screen:print(20, 30, "oki", white) -- [1]
         -- check for hit on horizontal line
         if hor and not(self.dir[2]==0) and self.y == p1[2] and
               is_bound(self.x, p1[1], p2[1]) then -- we hit it
            self.dir = {math.sgn(p2[1]-p1[1])*2, 0} -- follow
            if not self.cur_point then -- are we free roaming?
               self.cur_point = Fibers:resolve(self.x, self.y, p2)
            else self.cur_point = p1 end
            return
         -- check for hit on vertical line
         elseif not(self.dir[1]==0) and self.x == p1[1] and
               is_bound(self.y, p1[2], p2[2]) then -- we hit it
            self.dir = {0, math.sgn(p2[2]-p1[2])*2} -- follow
            if not self.cur_point then -- are we free roaming?
               self.cur_point = Fibers:resolve(self.x, self.y, p2)
            else self.cur_point = p1 end
            return
         end
      end
      hor = not hor
   end)

Hmpf. While prematurely optimizing everything, I overlooked a debug print to the screen that was executing every single iteration. I commented it out, and now my I'm back at a very easy 60 FPS.

What to learn from that? Lua is no way that slow, and make sure that you're doing only what you think you're doing.

While I'm giving advice:
If you use the fast method of developing and are not restarting LuaPlayer between tests do not use require. Use dofile. This was already pointed out by Sprak here but is important enough to mention again (and again, and again). I knew about it and even posted in that thread but still fell into the trap. It can cause very subtle bugs where some files are a new version while others still do the old thing.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group