Android Question Why my prg it's fast in debugging and slow in release?

gigi0ne

Member
Licensed User
Longtime User
hi, first.. sorry for my english.. it's terrible.. i know...

i have write my first program in b4a for use them in my restaurant. all it's ok, the program use the mysql db from my server via wifi and on debug release it's very fast.

when i compile the program in release mode.... the response from db it's very slow.. 2 or 3 seconds for 10 record.

Erel have you any idea?

i use a php with json (adapted from mysql example)

thank's
Luigi
 

eps

Expert
Licensed User
Longtime User
I would put some logging in place to work out where the slowdown is occurring. So log the current time in a few places.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
He said in RELEASE mode it is slow. While debugging it is fast.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
He said in RELEASE mode it is slow. While debugging it is fast.
The debugger network activity is light. As a bonus it prevents the device from turning the wifi power down to preserve battery.

I don't know whether this is the real cause of the slowness in this case. However the network latency of an active device is a few milliseconds and of an inactive device can be ~500ms.
 
Upvote 0

gigi0ne

Member
Licensed User
Longtime User
Find.... (the part of program incriminated..)

B4X:
    x = DateTime.Now
    If File.Exists(File.DirAssets, IM) Then
        L_Bitmap.Initialize(File.DirAssets,IM)
    Else
      L_Bitmap.Initialize(File.DirAssets,"default.png")
    End If
    Log("Create item End: " & (DateTime.Now-x))

on DEBUG from 9 to 20 ms

on RELEASE from 249 to 301 ms

Why?
thank's
Luigi
 
Last edited:
Upvote 0

eps

Expert
Licensed User
Longtime User
Maybe the Debug version doesn't do something that the Release version does, hence the slowdown? Is this in the Activity_Create sub? Can you please use the code tags on your code, it makes it a lot easier to read.
 
Upvote 0

gigi0ne

Member
Licensed User
Longtime User
Maybe the Debug version doesn't do something that the Release version does, hence the slowdown? Is this in the Activity_Create sub?

no... or yes and no.... it's on sub called from Activity_Create and other sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
That explains it.

The rapid debugger doesn't store the assets files inside the APK. This is a new feature named virtual assets folder. It allows the debugger to deploy your app with only the updated files. Loading images from the APK is slower than loading images from the external storage.

Make sure to load each bitmap once. For example in your code it can load the default image many times.
 
Upvote 0

gigi0ne

Member
Licensed User
Longtime User
ok.. i have try in this mode

B4X:
    x = DateTime.Now
    FN = IMG&".png"
    If MCache.IsOnDisk(IMG) Then
        L_Bitmap = MCache.GetBitmap(IMG,True)
    Else
        If File.Exists(File.DirAssets, FN) Then
                  L_Bitmap.Initialize(File.DirAssets,FN)
            MCache.PutBitmapOnDisk(IMG, L_Bitmap,"PNG",100)
        Else
              If MCache.IsOnDisk("default") Then
                    L_Bitmap = MCache.GetBitmap("default",True)
            Else
                  L_Bitmap.Initialize(File.DirAssets,"default.png")
                    MCache.PutBitmapOnDisk("default", L_Bitmap,"PNG",100)
            End If     
          End If   
    End If
    Log("Create item End: " & (DateTime.Now-x))

Same problem, in debug fro 1 to 10 msec in release from 200 to 300 ms
Log say

From memory cache: default
Create item end: 248

have you any idea?

thank's Luigi
 
Upvote 0

gigi0ne

Member
Licensed User
Longtime User
It is not a real problem. It is faster in debug mode because the files are not read from the APK but directly from the file system.


ok... i understand this... but if i put the file in cache.. why it's slow?
the image isn't ready from apk but from memory cache...
 
Upvote 0

gigi0ne

Member
Licensed User
Longtime User
Erel, Thank you so much for the fast responses and for the patience that you have.
I'm new to both of your program and basi (I am an old man who started with the machine language and then switched to C++ and Delphi)
can you post a small example of how to use the maps for the images?
thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Something like:
B4X:
Sub Process_Globals
 Dim images As Map
End Sub

Sub Activity_Create (FirstTime As Boolean)
 If FirstTime Then
  images.Initialize
 End If
...

Sub LoadAssetsImage(img As String)
 If images.ContainsKey(img) Then
  Return images.Get(img)
 Else
  Dim i As Bitmap = LoadBitmap(File.DirAssets, img)
  images.put(img, i)
  Return i
 End If
End Sub
 
Upvote 0

gigi0ne

Member
Licensed User
Longtime User
Something like:
B4X:
Sub Process_Globals
Dim images As Map
End Sub

Sub Activity_Create (FirstTime As Boolean)
If FirstTime Then
  images.Initialize
End If
...

Sub LoadAssetsImage(img As String)
If images.ContainsKey(img) Then
  Return images.Get(img)
Else
  Dim i As Bitmap = LoadBitmap(File.DirAssets, img)
  images.put(img, i)
  Return i
End If
End Sub


Thank's
 
Upvote 0
Top