Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
FB Instant game is very slow on iOS — Gideros Forum

FB Instant game is very slow on iOS

Hi guys,
So I'm back with an odd problem. My fb instant game is running very slow on iPhone, be it touch events or gtween events. The game otoh runs smoothly on android devices, even the entry-level ones. So what can the issue be? Thanks.

Comments

  • pm1891pm1891 Member
    edited September 2019
    Ok, so after looking at the forums for some advice, these are the following things I've changed:-

    1)I got rid of all touch events in my game. Now there's exactly one touch event added to the stage and I handle all touch events through it, like this
     
    function M:onMouseDown(event)
     
    	for k, v in pairs(mydata.touchHolder) do
    		if k and v and v:hitTestPoint(event.x, event.y) then
    			onMouseDown(v, event)		
                    end		
    	end
     
    end
    2)Then I'm trying to pool my bitmaps at the start of every scene like this. I'm not sure I'm doing this right as a speed bump has been negligible. So I would really appreciate some advice here.

    pool.lua
    function pool.create(newO, poolSize, Base)
     
    	if newO==150 then
     
    		local function newObject()
    			local obj = shape.rect(-dx,-dy,fullw+dx+dx,fullh+dy+dy)
    			return obj
    		end
     
    		poolSize = poolSize or 16
    		assert(newObject, "A function that returns new objects for the pool is required.")	
     
    		local freeObjects = {}
    		for _ = 1, poolSize do
    			table.insert(freeObjects, newObject())
    			if _==poolSize then 
    				print("bitmap loaded") 
    				local text = TextField.new(mydata.font1, "bitmap loaded")
    				stage:addChild(text)
    				text:setPosition(50, 50)
    			end
    		end
     
    		return setmetatable({
    				freeObjects = freeObjects,
    				newObject = newObject
    			},
    			poolmt
    		)
     
     
    	else
     
    		local function newObject()
    			local obj = Bitmap.new(Base:getTextureRegion(newO))
    			return obj
    		end
     
    		poolSize = poolSize or 16
    		assert(newObject, "A function that returns new objects for the pool is required.")	
     
    		local freeObjects = {}
    		for _ = 1, poolSize do
    			table.insert(freeObjects, newObject())
    			if _==poolSize then 
    				print("bitmap loaded") 
    				local text = TextField.new(mydata.font1, "bitmap loaded")
    				stage:addChild(text)
    				text:setPosition(50, 50)
    			end
    		end
     
    		return setmetatable({
    				freeObjects = freeObjects,
    				newObject = newObject
    			},
    			poolmt
    		)
     
     
     
    	end
    end
     
    function pool:obtain()
    	return #self.freeObjects == 0 and self.newObject() or table.remove(self.freeObjects)
    end
     
    function pool:free(obj)
    	assert(obj, "An object to be freed must be passed.")
     
    	table.insert(self.freeObjects, obj)
    	if obj.reset then obj.reset() end
    end
     
    function pool:clear()
    	for k in pairs(self.freeObjects) do
    		self.freeObjects[k] = nil
    	end
    end
     
    return pool

    levelselectscene.lua
    function LevelSelectScene:init(t)
    	if t then
    		print("LevelSelectScene: ", t)
    	end		
     
        local levelselect = mydata.levelselect
        local Base = mydata.Base
     
        -----------------------pooling bitmaps----------------------------
     
    	mydata.bitmaps = {}
    	mydata.bitmaps[1] = pool.create(77, 4, Base)  --["rect_btn6"] = 77,
    	mydata.bitmaps[2] = pool.create(86, 4, Base)  --["socialBase"] = 86,
    	mydata.bitmaps[3] = pool.create(98, 4, Base)   --["xClose"] = 98,
    	mydata.bitmaps[4] = pool.create(86, 4, Base)  --["socialBase"] = 86,
    	mydata.bitmaps[5] = pool.create(150, 4, Base)  --["socialBase"] = 86,
        mydata.bitmaps[6] = pool.create(42, 4, Base)  --["PopUpStar"] = 42,
        mydata.bitmaps[7] = pool.create(75, 4, Base)  --["rect_btn4"] = 75,
        mydata.bitmaps[8] = pool.create(70, 4, Base)   --["levelLives"] = 70
        mydata.bitmaps[9] = pool.create(66, 4, Base)   --["levelLives"] = 70
        mydata.bitmaps[10] = pool.create(56, 4, Base)   --["levelLives"] = 70
        mydata.bitmaps[11] = pool.create(117, 4, Base)   --["levelLives"] = 70
        mydata.bitmaps[12] = pool.create(80, 4, Base)   --["levelLives"] = 70
        mydata.bitmaps[13] = pool.create(124, 4, Base)   --["levelLives"] = 70
        mydata.bitmaps[14] = pool.create(126, 4, Base)   --["levelLives"] = 70
        mydata.bitmaps[15] = pool.create(132, 4, Base)   --["levelLives"] = 70
        mydata.bitmaps[16] = pool.create(69, 4, Base)  --["levelCoins"] = 69
     
     
    	self:addEventListener("enterBegin", self.onTransitionInBegin, self)
    	self:addEventListener("enterEnd", self.onTransitionInEnd, self)
    	self:addEventListener("exitBegin", self.onTransitionOutBegin, self)
    	self:addEventListener("exitEnd", self.onTransitionOutEnd, self)
    end
    The game is still very sluggish on older phones like iphone 5. Any and all advice is deeply appreciated.
  • hgy29hgy29 Maintainer
    Did you try to profile your code using gideros studio profiler ? It should point you to the right direction.

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • @hgy29 - I'm not sure how to use the profiler.
  • pm1891 said:

    @hgy29 - I'm not sure how to use the profiler.

    https://wiki.giderosmobile.com/index.php/Profiling

    Likes: pm1891

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    If you are unsure how to interpret the profiler log, post two versions here, one for android and one for iOS. If there is a severe performance issue on iOS, it should appear.
  • @hgy29 - Thanks. Will do.
  • @hgy29 - Sorry for being so late with the reply. I was struggling and failing with getting profiling to work with instant game. I feel like a complete idiot- seems I can do nothing right.

    Anyways, if anyone wants to take a look - here' the barebones of the game mechanics. Just game pieces dropping onto a board and looks very jerky on iOS messenger.
    zip
    zip
    iOS-basic.zip
    35K

    Likes: hgy29

    +1 -1 (+1 / -0 )Share on Facebook
  • @pm1891 sorry I can't help here :(

    Likes: pm1891

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • pm1891 said:

    @hgy29 - Sorry for being so late with the reply. I was struggling and failing with getting profiling to work with instant game. I feel like a complete idiot- seems I can do nothing right.

    Anyways, if anyone wants to take a look - here' the barebones of the game mechanics. Just game pieces dropping onto a board and looks very jerky on iOS messenger.

    Sorry that i have no comment for the code but here is some moral support:D

    Don't be harsh on yourself so much, this is called a learning curve. Sometimes it is logarithmic and so much difficult, sometimes not. Important thing is to not to quit and always try. Experience can not be gained without a difficulty. When you are depressed always look to the accomplishments that you have achieved, and not focus on your failures.
    Now show your skills to us Champion:D
    Note: If this one will not help watch Rocky 1 one more time to give you some quick energy:D
    +1 -1 (+3 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    pm1891 said:

    @hgy29 - Sorry for being so late with the reply. I was struggling and failing with getting profiling to work with instant game. I feel like a complete idiot- seems I can do nothing right.

    Well don't feel bad about it, honestly I had almost forgotten that I was never able to profile on iOS instant game.
    It is easy on IG/desktop, and it requires a bit of setup for IG/Android, but I am not sure it is even possible for IG/iOS.

    Anyway I tried your code on native iOS, just to get an idea of what consumes CPU. We can see there that there is a lot of function calls per frame, and that could be optimized somehow, but I would be surprised if it was the problem since iOS devices usually have decent CPU power. It could have been canvas size related (retina), but your code doesn't seem to manipulate a lot of pixels.

    It could be a general FPS issue: FPS clamped to 30 on iOS/IG, but hard to tell.

    I will look further and report back.

    +1 -1 (+3 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    Accepted Answer
    Ok, so it turns out that there is no practical way to profile under facebook app webview on iOS. However, I was able to profile a classic HTML5 export running on iOS safari. Unluckily it seems to work rather well on my iPhone (X), so I can't really tell what is supposed to be wrong...
    +1 -1 (+3 / -0 )Share on Facebook
  • pm1891pm1891 Member
    edited October 2019
    @MoKaLux - Thanks for taking a look. :)

    @talis - Thank you so much for your kind words. Means so much to me. No lie , I did watch "Eye of the tiger" on youtube. ;)

    @hgy29 - Thank you so much for devoting time to my project. In a way it's a relief to find out that profiling doesn't work on iOS. Makes me feel less of an idiot. Even more of a relief that the game works well on iPhone X. Maybe it's the older models that have this issue with lagging.
    I guess now I should just concentrate on optimizing all the functions that update per frame and hope for the best.

    Again, thank you all for taking an interest in my issue. This forum is the best.
    +1 -1 (+3 / -0 )Share on Facebook
  • Is your FB system outdated? You can try to update the app's system to the latest version. Please remember to also have a software update on your iPhone. Then clear all apps running in the background and re-launch the game to see if it is still running slow. If it does, then you could try to use related professional ios repair tools such as TunesKit iOS System Recovery. This software could resolve various iOS issues including iPhone and apps running slow.
Sign In or Register to comment.