Android app getting slower by use

Just starting out? Need help? Post your questions and find answers here.
hoerbie
Posts: 63
Joined: Sun Mar 17, 2019 5:51 pm
Location: DE/BY/MUC

Android app getting slower by use

Post by hoerbie »

Hi,

actually I've installed an SB app of about 10000 lines on some Android devices. The testers tell me, that the app is getting really slow if it is used intensive for some hours. Devices are mostly Sunmi M2 with Android 7.x, 4-core CPU 1.4GHz and 1GB Ram/8GB Rom, so not the high powered ones.
The app makes use of about 15 dialog windows that are opened, used and closed and repeating this. I'm using some structured arrays in the app, that are Dim'med and to empty them for the next action again Dim'med, or sometimes Redim'med. The app communicates with HttpRequest with a PB server to get and send json data, and sometimes the device goes to power save and the app awakes again.

So the question is to find out, why it gets slow. Until now I've never got friends with the browsers developer tools, and debugging on Android is difficult without Android Studio, that can't really be used when compiling from SB with Cordova.

Any tips from anyone?

Greets, hoerbie
percy_b
Posts: 7
Joined: Fri Oct 16, 2020 4:09 pm

Re: Android app getting slower by use

Post by percy_b »

Hi,
Try running your generated JavaScript through a linting tool. For example, see below:

https://www.jslint.com/
Dirk Geppert
Posts: 235
Joined: Fri Sep 22, 2017 7:02 am

Re: Android app getting slower by use

Post by Dirk Geppert »

Maybe this is a problem of open (hanging) Http connections?
Maybe a timeout can help to terminate them.
hoerbie
Posts: 63
Joined: Sun Mar 17, 2019 5:51 pm
Location: DE/BY/MUC

Re: Android app getting slower by use

Post by hoerbie »

@percy_b: Thanks, I will have a look, although I think this will need a lot more work with an SB app, than understanding the developer functions of a browser.

@Dirk: Thanks for the idea, but no, when the app does http communication, there is an info dialog, that is closed when communication is done.

To make it clear: the usability of the app gets slow, mostly when clicking a button or selecting a list entry there is a growing delay before there is a reaction of the app. This goes up to a situation, where you click a button, and 3 seconds later the actions starts, or you click on a list entry and its "selected" color comes seconds later.
So I think, it has something to do with growing memory use due to dialogs and gadgets or structured arrays, that maybe aren't fully cleared by SB or dojo.
For example the first opened window/dialog using #PB_Any is opened with a window ID of 100000 generated by SB, and these IDs are growing with use of the app and seem to be never reused, although the window was closed long time ago. And when opening the same window again later, and 20 other windows were used and closed between, the window gets the ID 100021, so using the app for some hours there can be hundreds or thousands of IDs wasted.
When I have time I will try to switch from #PB_Any to own constants for the window IDs, but at the moment my time is needed for other things...
Dirk Geppert
Posts: 235
Joined: Fri Sep 22, 2017 7:02 am

Re: Android app getting slower by use

Post by Dirk Geppert »

Because of the single thread architecture of javascript, you might be able to find out with time variables which procedure needs the longer computing time...
User avatar
skywalk
Posts: 45
Joined: Tue Feb 25, 2014 2:13 am
Location: Boston, MA

Re: Android app getting slower by use

Post by skywalk »

hoerbie wrote: Mon Sep 19, 2022 9:21 amFor example the first opened window/dialog using #PB_Any is opened with a window ID of 100000 generated by SB, and these IDs are growing with use of the app and seem to be never reused, although the window was closed long time ago. And when opening the same window again later, and 20 other windows were used and closed between, the window gets the ID 100021, so using the app for some hours there can be hundreds or thousands of IDs wasted.
When I have time I will try to switch from #PB_Any to own constants for the window IDs, but at the moment my time is needed for other things...
I think you are confusing Window Handle with PB's Window Number? #PB_Any is not supposed to carry empty objects formed by a gap in the number. Using #GadgetNumber=10000 and higher would create unnecessary bloat.

You could confirm by starting with a high #GadgetNumber=10000 and appending to that.
You could also try quantifying the slow down with a timed ~100ms equation that runs in the background on idle.
Observe the system settings if/when the calc begins to climb?
When working toward the solution of a problem, it always helps if you know the answer. ~ ?
An expert is one who knows more and more about less and less until he knows absolutely everything about nothing. ~ Weber
Fred
Site Admin
Posts: 1358
Joined: Mon Feb 24, 2014 10:51 am

Re: Android app getting slower by use

Post by Fred »

May be it's some objects which are not properly freed because a reference is still active, so the GC can't work as expected. It's difficult to pinpoint it like that unfortunately. You can easily connect Chrome and its debugger to your app running on Android, but I don't know if it will help.
hoerbie
Posts: 63
Joined: Sun Mar 17, 2019 5:51 pm
Location: DE/BY/MUC

Re: Android app getting slower by use

Post by hoerbie »

@Fred: Thank you for the tip, I didn't know about debugging between Chrome and Android, I will try to get it working.

@skywalk: Thanks, but coming from PB I don't think I'm confusing. I meant, that when I do something like

Code: Select all

winid = OpenWindow(#PB_ANY, ...)
the var winid becomes 100000. When using the command again, the winid is 100001 and so on. Working for some hours the winid is increased every time, no IDs of closed windows are reused.
It's the same with every gadget, with for example

Code: Select all

cbxid = ComboBoxGadget(#PB_Any, ...)
the cbxid becomes 100000 and the html-ID is dijit_form_ComboBox_0. When using the command again in a new window, the cbxid is 100001 (or with other ButtonGadgets etc. between it's maybe 100018) and the html-ID is dijit_form_ComboBox_1, and so on. Again working for some hours the cbxid and the number of dijit_form_ComboBox_xxx is increased every time.

@Dirk: Thanks again, but it's not my procedures that seem to get slow, but simply the reaction of the windows/dialogs to any user click. When there is the visual reaction of the gadget to the click, everything works fast, but you simply have to wait after a click, before anything happens.

Again: my idea was, that maybe some internals of SB or the used dojo system grow with this, because it mainly is the usability and reaction of any click that becomes really slow, as if it simply takes a lot of time to find out, what gadget was clicked, before my procedure "myfunction" of

Code: Select all

BindEvent(#PB_Event_Gadget, @myfunction....)
gets to do its job.

Maybe I'm wrong, I think I will try Freds tip for debugging it, or I will try to change all my own vars from pb_any to constants, but for now:

Greetings from the Oktoberfest 8-)
Fred
Site Admin
Posts: 1358
Joined: Mon Feb 24, 2014 10:51 am

Re: Android app getting slower by use

Post by Fred »

I will investigate this, it's a good tip, may be something is broken here and a foreach() takes too long overtime.
Fred
Site Admin
Posts: 1358
Joined: Mon Feb 24, 2014 10:51 am

Re: Android app getting slower by use

Post by Fred »

I just run a quick test but I can't see anything related to perf:

Code: Select all

For k = 0 To 1000
  Win = OpenWindow(#PB_Any, 0, 0, 200, 200, "Test")
  But = ButtonGadget(#PB_Any, 0, 0, 100, 30, "Hello")
  But2 = ButtonGadget(#PB_Any, 0, 40, 100, 30, "Hello")
  But3 = ButtonGadget(#PB_Any, 0, 80, 100, 30, "Hello")
  
  BindGadgetEvent(But, @Events())
  CloseWindow(Win)
Next

Win = OpenWindow(#PB_Any, 0, 0, 200, 200, "Test")
But = ButtonGadget(#PB_Any, 0, 0, 100, 30, "Hello")
But2 = ButtonGadget(#PB_Any, 0, 40, 100, 30, "Hello")
But3 = ButtonGadget(#PB_Any, 0, 80, 100, 30, "Hello")

BindGadgetEvent(But, @Events())
If you comment the CloseWindow(), you have indeed has a lag in event, but it's because your have 1000 windows to process. May be some windows stay hidden or something ?
Post Reply