iOS app has begun opening very slowly

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

iOS app has begun opening very slowly

Post by rcmills » Wed May 29, 2019 8:44 pm

I have been working on an iOS app for a good while. It has recently begun opening very slowly on my iPhone 6+
It used to open inside of 3 seconds, but now takes more than 11-12 seconds from splash screen to full opening.

It includes 5 fairly large text data files (around 4+ MB each) but opened fast with all of them before. I hadn't made any major changes in the code, only slight debugging just before the problem cropped up. Returning to an earlier version of the app (pre-debugging) restored the speed of opening, but of course, has the bugs. The app size is under 56 MB on my Mac disk.

I am using LC Indy 9.0.1 and Xcode 9.4.1 (9F2000).

Has anyone else had a similar issue?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: iOS app has begun opening very slowly

Post by jmburnod » Wed May 29, 2019 9:55 pm

Hi rcmills
I remembrer that Jacqueline said that a short preopenstack with a send in time is better than a long preopenstack message. I tested it with success.
You may make your preopenstack shortest as possible and use a send in time for next step
Something like that:

Code: Select all

on preOpenStack
   if  the environment <> "mobile" then
      set the loc of this stack to the screenloc
   end if
   send "doAfterPreOpenStack" to me in 1 milliseconds 
end preOpenStack

on doAfterPreOpenStack
   --...
end doAfterPreOpenStack
Best regards
Jean-Marc
https://alternatic.ch

rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

Re: iOS app has begun opening very slowly

Post by rcmills » Thu May 30, 2019 12:17 am

Thanks Jean-Marc,

I tried it, and the relevant code now reads:

Code: Select all

on preOpenStack
   set acceleratedRendering of this stack to true
   send "doAfterPreopenStack" to me in 1 milliseconds
end preOpenStack

on doAfterPreopenStack
   lock screen
   if the environment is "mobile" then
      insert the script of button "Common" of this card into back
      insert the script of button "Profile" of this card into back
      
      local tOrientations
      put "portrait,portrait upside down,landscape left,landscape right" into tOrientations
      mobileSetAllowedOrientations tOrientations
      set the fullscreenmode of this stack to "noScale"
      
      updateProfiles  -- adjust profiles for actual device screen size
      
      fwmobCreateNativeScroller the long id of fld "book text"
      fwmobResizeNativeControls
   end if
   
   get setUpFieldSizes(the rect of this cd)
   get readDataFile(false)
   unlock screen
end doAfterPreopenStack
Unfortunately, it seems that the change has only shaved off maybe a second or two of opening time.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: iOS app has begun opening very slowly

Post by LCMark » Thu May 30, 2019 11:29 am

@rcmills: Has the content of the text files, or what readDataFile() does, changed since earlier versions which are quicker?

rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

Re: iOS app has begun opening very slowly

Post by rcmills » Thu May 30, 2019 3:44 pm

Not to any significant degree. The 5 text files are identical to prior to the speed change, and are not read by readDataFile(), though they are loaded with the app during the start up, I assume. Only one (at a time) of them is read in here (the 4 lines beginning with:
get "/mb.version." & fld "version label" & ".txt").

There is a data.txt file with around 5 or 6 lines of data which restore the last state of the app. The code of the data reading subroutine is here, and is also not changed since before the speed change.

Code: Select all

function readDataFile flag
   
   put getDataFilePath("data.txt") into tFile
   put URL tFile into tData

   repeat with i = 1 to 5
      if line i of tData is empty
      then
         put "Gen 1 1" into line 1 of tData
         put "KJV" into line 2 of tData
         put 15 into line 3 of tData
         put "Arial" into line 4 of tData
         put 0 into line 5 of tData
      end if
   end repeat
   
   put word 1 of tData into tBook
   put word 2 of tData into tChapter
   put line 2 of tData into fld "version label"
   
   get "/mb.version." & fld "version label" & ".txt"
   put "file:/" & specialfolderpath("engine") into sFolder
   put (sFolder & it) into tFile
   put URL tFile into bibleText
   
   get line 3 of tData
   if it < 8 then get 8
   set the textSize of fld "book text" to it
   
   set the textFont of fld "book text" to line 4 of tData
   
   get showBookChap(tBook,tChapter,true)   -- true means don't choose verse
   set the vScroll of fld "book text" to line 5 of tData
   if the environment is "mobile" then
      fwmobCreateNativeScroller the long id of fld "book text"
      fwmobResizeNativeControls
   end if
   
   put "file:/" & specialFolderPath("documents") & "/bibleAppDocs/searchHistory.txt" into tFileName
   if the environment is "mobile"
   then put "file:/" & specialFolderPath("documents") & "/searchHistory.txt" into tFileName
   if fld "history" is empty then put URL(tFileName) into fld "history"
   
   saveDataFile
end readDataFile
Thanks.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: iOS app has begun opening very slowly

Post by LCMark » Thu May 30, 2019 4:24 pm

@rcmiills: Okay so if the data files haven't changed (which wasn't relevant anyway), and the startup code hasn't changed then:

- Has the stackfile changed? e.g. has it got bigger, more objects added
- Has the version of LC you are using changed?
- Has the OS version on your device changed?

I'm guessing it must be something in the stackfile itself which has changed - otherwise you wouldn't observe the faster speed with previous versions :|

rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

Re: iOS app has begun opening very slowly

Post by rcmills » Fri May 31, 2019 1:45 pm

I finally reverted to the last faster opening file, and slowly re-debugged, checking at each step on the simulator for opening times. I have re-acheived a (hopefully) bug free state, and still have a good (around 1 second) opening time. The file size is around 237 KB. The slow loading file was around 296 KB, though I am not sure why it was so much larger. I can't recall putting enough new code in to make that difference, but must assume I was more efficient in the second debugging.

Many thanks for all the advice :)

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: iOS app has begun opening very slowly

Post by bwmilby » Fri May 31, 2019 2:56 pm

You no longer need to manually include the common and profile library scripts in LC 9 like you are doing. That was something that I had to do before the IDE was updated to support those inclusions in mobile. You also probably are going to want to verify the fullscreenmode since it may not work as expected on another size device.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

Re: iOS app has begun opening very slowly

Post by rcmills » Fri May 31, 2019 5:07 pm

Thanks, Brian.

Does that mean I don't need to include the devControls substack, either?

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: iOS app has begun opening very slowly

Post by bwmilby » Fri May 31, 2019 5:17 pm

It isn’t needed in the built app but does make setting up the profiles easier in the IDE. Depending on how complex the UI is, it may be easier to just write the resizeStack handler to account for orientation and size changes manually.

Here is another mobile demo that has a manual resizeStack handler. It doesn’t change things based on orientation directly, but does have some code that adjusts based on width. It uses neither GM nor PM.
https://github.com/bwmilby/mobileDemo
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

Re: iOS app has begun opening very slowly

Post by rcmills » Fri May 31, 2019 5:27 pm

Thanks very much!

Post Reply

Return to “iOS Deployment”