B4J Question Application speed suffering?

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
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.
 

Erel

Administrator
Staff member
Licensed 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.
 

sorex

Expert
Licensed 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?
 

sorex

Expert
Licensed 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

AnandGupta

Well-Known Member
Licensed 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
 

Erel

Administrator
Staff member
Licensed 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.
 

Erel

Administrator
Staff member
Licensed 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
 
I don't use font awesome, but I do change the font using CSS to a local file in the Assets folder. But that's not the issue in my case. Even the older app without colorful design used a special font.
 
Top