Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Corona/LUA Runtime - Great optimization potential?
Started by torbenratzlaff Jul 20 2015 07:59 AM

30 replies to this topic
[TOPIC CONTROLS]
Page 2 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,373 posts
  • Corona SDK

for what it's worth..., just be sure to benchmark any proposed trig lookup on an actual device, cuz it often doesn't pay off.  math.cos (et al) are native calls, whereas a table lookup needs:  conversion of the angle to index, a proper modulo handling negative values, and finally the table indexing itself.  and all that interpreted indexing code often works out to be slower than just calling math.cos directly!  so you may lose accuracy AND performance.



[TOPIC: post.html]
#27

ponywolf

[GLOBAL: userInfoPane.html]
ponywolf
  • Contributor

  • 274 posts
  • Corona SDK

I did update Bone.lua to use a single lookup table, but I agree since Corona itself is capped at 30 or 60FPS unless you have performance issues on a device there's no reason to implement it. And you do see "clicking" into angles with slow rotations of big objects.

 

Here's a snippet of the lines I added. It's pretty easy to comment/uncomment to see it both ways.

 

I really haven't had a chance to evaluate your fork of the spine runtimes, because I'm working on a game release right now and we're trying to lock things down and I don't want to introduce any new code. I will take a peek the second things slow down.


local Bone = {}

local lookup = {}
for i = 0, 359 do 
   lookup[i] = math.sin( math.pi / 180 * i ) 
end

function Bone.new (data, skeleton, parent)
	if not data then error("data cannot be nil", 2) end
	if not skeleton then error("skeleton cannot be nil", 2) end

	local self = {
		data = data,

-- continued --
			self.worldScaleY = self.scaleY
			self.worldRotation = self.rotationIK
			self.worldFlipX = skeletonFlipX ~= self.flipX
			self.worldFlipY = skeletonFlipY ~= self.flipY
		end
		
--local radians = math.rad(self.worldRotation)
--local cos = math.cos(radians)
--local sin = math.sin(radians)
    
    local angle = (self.worldRotation - self.worldRotation % 1) % 360
    local cos = lookup[(angle+90) % 360]
    local sin = lookup[angle]


[TOPIC: post.html]
#28

torbenratzlaff

[GLOBAL: userInfoPane.html]
torbenratzlaff
  • Contributor

  • 404 posts
  • Corona SDK

Searched the web for some validation and found a few (not Corona) test that other developers shared.

 

The conclusion seems to be, that it depends which framework you use and how it handles the math calls.

 

But the difference is so small in comparison to other optimizations (e.g. localising) that it isn't worth the effort and downsides to use a lookup table instead of a localized math function.



[TOPIC: post.html]
#29

blomjens1

[GLOBAL: userInfoPane.html]
blomjens1
  • Contributor

  • 124 posts
  • Corona SDK

@no2games

did you upload your spine wrapper to github ? 
i need for a good spine wrapper 

Regards 
Jens



[TOPIC: post.html]
#30

ponywolf

[GLOBAL: userInfoPane.html]
ponywolf
  • Contributor

  • 274 posts
  • Corona SDK

@blomjens1 Not pushed it github yet, but it's pretty much the code I posted on the first page of this thread...



[TOPIC: post.html]
#31

blomjens1

[GLOBAL: userInfoPane.html]
blomjens1
  • Contributor

  • 124 posts
  • Corona SDK

ok thanks!




[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]