B4J Question Application speed suffering?

MegatenFreak

Active Member
Licensed User
Hello.
The company that uses my app has a lot of low-mid range systems. Now, before, the app was super fast everywhere, but ever since we've done visual design to make it look better (mainly using CSS and sometimes JAVA code within the module) it's become really slow on their weaker systems. Forms load slower, and even when typing in a TextArea the characters appear slowly.
I was wondering if there are any guidelines or hints I could use to optimize my application and make it faster??
Thanks a lot in advance.
 

sorex

Expert
Licensed User
Longtime User
what I noticed a few days ago is that if you use non default fonts - for example fontawesome for button icons - things like loadlayout become slower.
(from instant to 2-3 seconds, even when the main form already loaded the font for a button icon the delay is still there on later loadlayouts)

but once the form or panel is loaded it should be fast at later appearences.

I've never seen delays in textfields/areas myself.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
what I noticed a few days ago is that if you use non default fonts - for example fontawesome for button icons - things like loadlayout become slower.
(from instant to 2-3 seconds, even when the main form already loaded the font for a button icon the delay is still there on later loadlayouts)
Sounds strange. Try to reproduce it in a small project.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Try to reproduce it in a small project.

I did, with a layout with just 1 fontawesome button.

If you change the font to default it's a lot faster.

it's like the font gets (re-)loaded everytime a layout contains a reference to it.

Do you want me to add it to the bugs/features sub forum for investigation?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
here you go...

button 1 loads a layout with normal fonts

button 2 load a layout with fontawesome icon buttons and pause 2-5 seconds

button 3 load another layout with fontawesome icon button but there's no delay if you used button 2 first, if you do it before button 2 you have the delay aswell

so it's not re-loading the font but the initial load takes time even if it's only 1 button in the layout


maybe loading a small layout after the main form is show can bypass this delay for the first layout that gets loaded by the end user.
 

Attachments

  • fontSlowdown.zip
    5.6 KB · Views: 119
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
so it's not re-loading the font but the initial load takes time even if it's only 1 button in the layout
Yes you are right. There is a notable delay if we click as you described.
I put logs and noted time delay ,
B4X:
    Log(DateTime.Now)
    pFontawesome.LoadLayout("fontawesome")
    Log(DateTime.Now)

Maybe Erel and throw lights on it now.

Regards,

Anand
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
@sorex this is not related to this thread and it is not really related to LoadLayout. It takes a few hundred milliseconds to load font awesome. However it is only needed once and it doesn't affect the app performance.
On my computer it takes about 200ms.

You can explicitly load the font yourself with:
B4X:
Dim n As Long = DateTime.Now
    Dim x As B4XFont = xui.CreateFontAwesome(10)
    Log(DateTime.Now - n)
The layout will then be loaded immediately.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can load the font asynchronously:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    MainForm.RootPane.LoadLayout("main") 'layout without FontAwesome
    Dim jo As JavaObject = Me
    jo.RunMethod("loadFontAwesome", Null)
    Wait For FontAwesome_Loaded (Success As Boolean)
    Log($"Font loaded: ${Success}"$)
End Sub

#if Java
import java.util.concurrent.Callable;

public static void loadFontAwesome() {
   BA.runAsync(ba, mostCurrent, "fontawesome_loaded", new Object[] {false}
       , new Callable<Object[]>() {
                   @Override
                   public Object[] call() throws Exception {
                           anywheresoftware.b4j.objects.JFX.loadFontAwesome();
                       return new Object[] {true};
                   }
               }); }
#End If
 
Upvote 0
Top