Android Question Slow loading CLV with table [SOLVED]

AHilberink

Active Member
Licensed User
Longtime User
Hi,

I am having trouble by speeding up the loading of my CLV.

Attached I have made a small example of my project. Just 35 lines to load, but because of the table inside the lines it is very slow.

I hope someone will have a look and may be have some advise to improve the loading speed.

Kind regards,
André
 

Attachments

  • ExampleCLV.zip
    47.7 KB · Views: 91

emexes

Expert
Licensed User
Attached I have made a small example of my project. Just 35 lines to load, but because of the table inside the lines it is very slow.

Creating the maps should be no problem, but the bit where you write (insert) the maps into a database, that's probably where it's getting bogged down.

I couldn't see a .db file so I didn't actually try running your example, but given you've put the effort into creating the example... give me a few minutes... 🍻

ps when you say "table inside the lines"... what lines?
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Creating the maps should be no problem, but the bit where you write (insert) the maps into a database, that's probably where it's getting bogged down.

I couldn't see a .db file so I didn't actually try running your example, but given you've put the effort into creating the example... give me a few minutes... 🍻

ps when you say "table inside the lines"... what lines?

Hi Emexes,

The part of creating the DB within the Main is just to fill the example. If you hit the Button, you will open the part with the CLV (Module Opdrachten) which is slow.

Thanks for helping me.

Kind regards,
André
 
Upvote 0

emexes

Expert
Licensed User
Thanks for helping me.

Lol thanks but let's not count our chickens just yet 🙃 I'm currently trawling through B4XGoodies trying to locate libraries that you have and I don't (yet).

1671578448034.png
 
Upvote 0

emexes

Expert
Licensed User
Progress report: close, but no cigar (yet)

1671585355430.png


Log output:
Logger connected to:  TCL 5009A
--------- beginning of main
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (opdrachten) Create, isFirst = true **
Table: 0
Error occurred on line: 177 (Opdrachten)
java.lang.RuntimeException: Class instance was not initialized (table)
    at anywheresoftware.b4a.debug.Debug.shouldDelegate(Debug.java:242)
    at b4a.example.table._getrowheight(table.java:132)
    at b4a.example.opdrachten._createitem(opdrachten.java:456)
    at b4a.example.opdrachten._activity_create(opdrachten.java:414)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
    at b4a.example.opdrachten.afterFirstLayout(opdrachten.java:105)
    at b4a.example.opdrachten.access$000(opdrachten.java:17)
    at b4a.example.opdrachten$WaitForLayout.run(opdrachten.java:83)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
** Activity (opdrachten) Resume **

I have some cheese and tomato sandwiches under the griller = I'll be back in half an hour 🍻
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
Righto, I've gotten as far as tblAanvulling1 not being initialized. I can see it in layout file item.bal

I moved p.LoadLayout("item") up to before the tblAanvulling1 properties were used, but now getting error:

Log output:
Logger connected to:  TCL 5009A
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (opdrachten) Create, isFirst = true **
Panel size is unknown. Layout may not be loaded correctly.
Error occurred on line: 173 (Opdrachten)
java.lang.RuntimeException: java.lang.RuntimeException: Cannot convert: class anywheresoftware.b4a.objects.ImageViewWrapper, to: class anywheresoftware.b4a.objects.ButtonWrapper
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:155)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:314)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at b4a.example.opdrachten._createitem(opdrachten.java:438)
    at b4a.example.opdrachten._activity_create(opdrachten.java:414)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
    at b4a.example.opdrachten.afterFirstLayout(opdrachten.java:105)
    at b4a.example.opdrachten.access$000(opdrachten.java:17)
    at b4a.example.opdrachten$WaitForLayout.run(opdrachten.java:83)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.RuntimeException: Cannot convert: class anywheresoftware.b4a.objects.ImageViewWrapper, to: class anywheresoftware.b4a.objects.ButtonWrapper
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:398)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:442)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:442)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:133)
    ... 28 more

If you could restore your example project zip to a new empty folder name (ie not over the top of your existing example project) and confirm that it still works, that'd be great.
 
Upvote 0

PaulMeuris

Active Member
Licensed User
If this code is not executed the app starts fast.
B4X:
    If(VanafStart=False) Then
        Dim p As B4XView = CreateItem(0,0,"","","","","","","")
        OpdrachtTable.Add(p, expandable.CreateValue(p, "some value"))
        DatumLong=DateTime.Now
        DisplayDatum=DateTime.Date(DateTime.Now)
        WisselDatum
    End If
The CreateItem subroutine throws an error.
B4X:
Sub CreateItem(Opdracht As Int, Ingetrokken As Int, Eindeuitvoering As String, Klantnaam As String, Adres As String, Tijd As String, Omschrijving As String, Reeds As String, Toelichting As String) As B4XView
    Dim p As B4XView = xui.CreatePanel("")

    Log("Table: "&Opdracht)
    'EigenFuncties.Aanvulling(Bericht)
    Dim Rows As Int=Main.SQL1.ExecQuerySingleResult("SELECT COUNT(*) FROM Dumptabel WHERE OpdrachtID="&Opdracht)
The variable Opdracht is an ID field of the Dumptabel (and not a table as the log suggests).
When is the Dumptabel filled?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Unfortunately, your project does not work as it is.
I got the same error as emexes.
I had to modify in the CreateItem routine the height values to fixed values.
Then i got another error, because in your layout you have an ImageView, but in the code you declared it as a Button !?
Then the program runs.
I checked the different parts of the program in Release mode.
For the tests i removed all Sleep(0) and commented the call to the ProgressBar.
To load the program it takes: 8.7 seconds
Then i commented the filling of the Tables and it takes: 3 s.
Then i uncommented the filling of the Tables but left tblAanvulling1.ClearAll commented (not needed), it takes: 6.1 s.
Therefore filling the Tables takes about the same time as filling the CLV.

I will investigate further to see if the filling of the Tables can be optimized.
A few questions:
- Are the column widths of all tables the same ?
- What is row number of the longest table ?
- Will there be Tables needing horizontal scrolling ?

Depending on the answers, the code for the Tables could be simplified.
Creating very simple tables instead of using the Table CustomView.
 
Last edited:
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Unfortunately, your project does not work as it is.
I got the same error as emexes.
I had to modify in the CreateItem routine the height values to fixed values.
Then i got another error, because in your layout you have an ImageView, but in the code you declared it as a Button !?
Then the program runs.
I checked the different parts of the program in Release mode.
For the tests i removed all Sleep(0) and commented the call to the ProgressBar.
Tu load the program it takes: 8.7 seconds
Then i commented the filling of the Tables and it takes: 3 s.
Then i uncommented the filling of the Tables but left tblAanvulling1.ClearAll commented (not needed), it takes: 6.1 s.
Therefore filling the Tables takes about the same time as filling the CLV.

I will investigate further to see if the filling of the Tables can be optimized.
A few questions:
- Are the column widths of all tables the same ?
- What is row number of the longest table ?
- Will there be Tables needing horizontal scrolling ?

Depending on the answers, the code for the Tables could be simplified.
Creating very simple tables instead of using the Table CustomView.


Hi,

Thanks you all for helping me.

I don't understand why the example is not working (tried it on 2 different devices and even download the zip and tried the project from a new map).
But you got it working.

The answer to your questions are:
I will investigate further to see if the filling of the Tables can be optimized.
A few questions:
- Are the column widths of all tables the same ?
Yes, they are al the same

- What is row number of the longest table ?
It depends on the order, but I think the maximum will be about 4

- Will there be Tables needing horizontal scrolling ?
No, with the maximum of 4 it will be not needed

I hope you can help me to speed it up.

Kind regards,
André
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
If this code is not executed the app starts fast.
B4X:
    If(VanafStart=False) Then
        Dim p As B4XView = CreateItem(0,0,"","","","","","","")
        OpdrachtTable.Add(p, expandable.CreateValue(p, "some value"))
        DatumLong=DateTime.Now
        DisplayDatum=DateTime.Date(DateTime.Now)
        WisselDatum
    End If
The CreateItem subroutine throws an error.
B4X:
Sub CreateItem(Opdracht As Int, Ingetrokken As Int, Eindeuitvoering As String, Klantnaam As String, Adres As String, Tijd As String, Omschrijving As String, Reeds As String, Toelichting As String) As B4XView
    Dim p As B4XView = xui.CreatePanel("")

    Log("Table: "&Opdracht)
    'EigenFuncties.Aanvulling(Bericht)
    Dim Rows As Int=Main.SQL1.ExecQuerySingleResult("SELECT COUNT(*) FROM Dumptabel WHERE OpdrachtID="&Opdracht)
The variable Opdracht is an ID field of the Dumptabel (and not a table as the log suggests).
When is the Dumptabel filled?

Hi,

Thanks for the help and your reply.

If this code is not executed the app starts fast.
This part is neccesary to start the filling of today and I cannot disable it.

The variable Opdracht is an ID field of the Dumptabel (and not a table as the log suggests).
This is correct, sorry for the Log("Table: "....), but this was made during testing by me

When is the Dumptabel filled?
This filling is done at lin 110: EigenFuncties.Aanvulling(res.GetInt("OpdrachtID")) of module Opdrachten

I will investigate why you all got errors by running my example. Maybe a difference between my 11.8 and v12?

Kind regards,
André
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
One more question:
- Do you need to select any row ?
- Do you need any header or cell click event ?

Hi Klaus,

- Do you need to select any row ?
I don't need to select any row
- Do you need any header or cell click event ?
I don't need click on a header or cell. I would be nice to have a click event on the whole table

Kind regards,
André
 
Upvote 0

emexes

Expert
Licensed User
Well, I tried using plain old SQL library in place of SQLCipher library, but that made no noticeable speed difference.

I am feeling like the speedup would be to grab all the data from the database in one gulp, and then distribute from the temporary copy in memory, to all of those tables on the clv.

B4X:
'takes ~150 ms (x 36)
Dim tempquery As String = "SELECT Actie, Omschrijving, Aantal FROM DumpTabel WHERE OpdrachtID=" & Opdracht

'takes ~200 ms (x 1)
Dim tempquery As String = "SELECT Actie, Omschrijving, Aantal, OpdrachtID FROM DumpTabel"
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
In the real-life app it is exactly the same. There is no remote database.

Then perhaps the belt-and-braces generality of SQLite is over-engineering the process (sledgehammer to crack a walnut).

An Array/List/Map of user-defined-type might be simpler. Saved to CSV file occasionally, just in case battery goes flat etc (bonus - can load CSV into spreadsheet or upload to Google Sheet for easy(ish) viewing and debugging).
 
Upvote 0
Top