iOS Question Release version not improving processing speed

jai

Active Member
Licensed User
Longtime User
Hi,

I have a large app that has been released for Android as well as iOS. It is very intensive in computations. Both, B4A and B4i versions are almost identical except for some obvious programming differences for certain functions. Most noticeable difference, however, is the processing speed of the released versions on comparable devices.

I have tested the processing times for certain high-computation modules in debug modes of each system and they are very close. Both platforms take about the same amount of processing time for these modules. But the released versions are far apart. The Android release version becomes 2-4 times faster than iOS. Some results that take about 10 seconds in the Android release version takes over a minute in iOS version. The modules I have clocked are purely computational with lots of functions and repetitions. Android release version speed increases significantly from the debug version but iOS release app increases only very slightly. These modules are quite intertwined and cannot be easily extracted for a example.

I have been trying some suggestions made in similar posts, such as-

1. Making sure all break points are cleared
2. Using the Clean Project option before each compilation

Clean Project has been necessary for the app to run properly because of the size of the code but neither of these has made any difference to the speed. Is there something else I can do that may help rev up the iOS release version?

Thanks
 

jai

Active Member
Licensed User
Longtime User
The following is a small extraction of one of the modules time tested in bebug made-
B4X:
Case 5

                        'Needs Analysis Report Tapped
                        '***************Capital Needs Evaluations**************
                        If Profile="Retirement" Then
                            Dim SaveInitValue(11) As Int 
                            Dim AnalysisLoopIndex As Short 
                            Dim InsSet As Short 
                            Dim TryAmount As Int 'Automated Insurance Analysis amount
                            If Proj(431,Span)<0 Then
                           
                                '******Retirement Postponement **********
                                SaveInitValue(1)=InputValue(3)
                                SaveInitValue(2)=InputValue(4)
                                For AnalysisLoopIndex=1 To 25
                                    If InputValue(3)>0 Then InputValue(3)=InputValue(3)+1
                                    If InputValue(4)>0 Then InputValue(4)=InputValue(4)+1
                                    SaveInitValue(0)=AnalysisLoopIndex 'Years of postponement
                                    ComputeTax
                                    If Proj(431,Span)>=0 Then AnalysisLoopIndex=25 'Exit when turns positive
                                Next
                                InputValue(3)=SaveInitValue(1)
                                InputValue(4)=SaveInitValue(2)
                                ComputeTax
                               
                                '******Increasing Earnings evaluation(Business Income)*******************
                                SaveInitValue(3)=InputValue(185) 'Save for restoring
                                AddAmount=0:ReduceAmount=0
                                'Pmt=FV*r/(((1+r)^n)-1)
                                TryAmount=Abs(Proj(431,Span))*CashMgmtRate/(Power(1+CashMgmtRate,Span)-1)
                                InputValue(185)=SaveInitValue(3)+TryAmount 
                                ComputeTax
                                'Dim n As Long = DateTime.Now
                                For AnalysisLoopIndex=1 To 25
                                    If Proj(431,Span)>=0 Then
                                        If Proj(431,Span)<10000 Then 
                                            AnalysisLoopIndex=25
                                        Else
                                            ReduceAmount=ReduceAmount/4
                                            If ReduceAmount=0 Then ReduceAmount=(Abs(Proj(431,Span))+5000)*CashMgmtRate/(Power(1+CashMgmtRate,Span)-1) 
                                            TryAmount=TryAmount-ReduceAmount
                                            InputValue(185)=SaveInitValue(3)+TryAmount
                                        End If
                                    Else
                                        AddAmount=Abs(Proj(431,Span))*CashMgmtRate/(Power(1+CashMgmtRate,Span)-1) 'Set initial AddAmount to PV of final shortage plus 10%
                                        TryAmount=TryAmount+AddAmount
                                        InputValue(185)=SaveInitValue(3)+TryAmount
                                    End If
                                    ComputeTax
                                Next
                                SaveInitValue(4)=f.PositiveOnly(InputValue(185)-SaveInitValue(3)) 
                                InputValue(185)=SaveInitValue(3) 
                                ComputeTax                               

                                '******Reduce Expense *******************
                                SaveInitValue(5)=InputValue(331)
                                'Pmt=FV*r/(((1+r)^n)-1)
                                TryAmount=(Abs(Proj(431,Span))*CashMgmtRate/(Power(1+CashMgmtRate,Span)-1))/2
                                InputValue(331)=SaveInitValue(5)-TryAmount 'PV of shortage
                                ComputeTax
                                For AnalysisLoopIndex=1 To 25
                                    If Proj(431,Span)>=0 Then
                                        If Proj(431,Span)<10000 Then 
                                            AnalysisLoopIndex=25
                                        Else
                                            AddAmount=((Abs(Proj(431,Span))+5000)*CashMgmtRate/(Power(1+CashMgmtRate,Span)-1))/4
                                            TryAmount=TryAmount-AddAmount
                                            InputValue(331)=SaveInitValue(5)-TryAmount
                                        End If
                                    Else
                                        AddAmount=(Abs(Proj(431,Span))*CashMgmtRate/(Power(1+CashMgmtRate,Span)-1))/4 'Set initial AddAmount to PV of final shortage plus 10%
                                        If AddAmount<25 Then AddAmount=25
                                        TryAmount=TryAmount+AddAmount
                                        InputValue(331)=SaveInitValue(5)-TryAmount
                                    End If
                                    ComputeTax
                                Next
                                SaveInitValue(6)=Abs(InputValue(331)-SaveInitValue(5))
                                If SaveInitValue(6)>Proj(468,1) Then  SaveInitValue(6)=0 'Not enough expenses to be able to save to cover the deficit
                                InputValue(331)=SaveInitValue(5)
                                ComputeTax               
                            End If
                        End If
                       
                        '*************End Needs evaluations***********

The ComputeTax mentioned in the above code is a subroutine with about 1k lines of computations and functions called for computations in other modules.

The above app segment takes from 10-60 seconds in the debug mode depending on the plan data being analyzed

I am not sure how much this helps except that it reflects the type of conditions and computations in this app.

The important part of this puzzle is that the code for computations and functions is the same in B4A and B4i verions. They both run with similar speed in the debug version but the release version of B4A is much faster than B4i.
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
What is your iDevice? In real life test of my app, iPhone 4 is far slow compare to iPhone 5 and 6, even it's just layout adjustment. Maybe that is reason?
 
Upvote 0

jai

Active Member
Licensed User
Longtime User
I use iPhone4S, iPhone5 and iPad2 in testing. The speed of the device is understandable. I used iPhone5 mostly for testing this problem. I believe there may be some other factors that are playing out in the relative slowness.

On certain menus I have multiple options. They all go through the same layout but the slowness is most prominent in options with very high calculation rate. I don't think that this a layout issue.

This slowness does not happen on the B4A version on Android devices.

Let me clarify the core of my question - Is my assumption that the release version should be faster than the debug version correct? On Android it clearly is but not so clear on iOS.
 
Upvote 0

jai

Active Member
Licensed User
Longtime User
Actually, I have not paid much attention to the declarations. Perhaps there is something missing or inappropriate in my declaration. Here is what I have after the ApplicationLabel and the version-
B4X:
    #iPhoneOrientations: Portrait

    #iPadOrientations: Portrait
    #PlistExtra: <key>UIFileSharingEnabled</key><true/>
    #PlistExtra: <key>UIViewControllerBasedStatusBarAppearance</key><false/>
    #PlistExtra: <key>UIFileSharingEnabled</key><true/>
   
    '***Give iOS info as a candidate to open text files   
    #PlistExtra:<key>CFBundleDocumentTypes</key>
    #PlistExtra:<array><dict><key>CFBundleTypeIconFiles</key><array/>
    #PlistExtra: <key>CFBundleTypeName</key><string>txt File</string>
    #PlistExtra:<key>LSItemContentTypes</key><array>
    #PlistExtra:<string>public.plain-text</string>
    #PlistExtra:</array></dict></array>

Please let me know your thoughts.
 
Upvote 0
Top