Page 1 of 1

Very slow GetDirectoryEntry

Posted: Tue Apr 28, 2026 8:32 pm
by amyren
Just discovered that one of my programs after an update now used extremely long time to start up. This was the first time compiled with the new apk compiler version.
First just a white screen for a minute or so, then the bcpic is loaded and then a few more minutes before the main screen is fully loaded.

I had done quite a few changes in my code so I tried reverting piece by piece to find what new caused this slowdown.
Then I just stripped down the code to a minimum to test, but still it was dead slow.

Turns out it is the usage of GetDircectoryEntry that causes this.
I have 3 linked directories with containing 371 files, about 4.5MB in total.

Adding these files to Asset and using GetAsset instead the app loads in two seconds.

Just for debugging I did test to keep the directory links in my code (but still use GetAsset). Then the app start with a white screen for 30 seconds, then the bgpic and the rest of the main screen loads as normal.

Re: Very slow GetDirectoryEntry

Posted: Tue Apr 28, 2026 8:56 pm
by plouf
...unfortunately these crap these days should be
Debugged first by total disabling antivirus craps..

It has high probabilty...

Re: Very slow GetDirectoryEntry

Posted: Wed Apr 29, 2026 2:31 pm
by amyren
plouf wrote: Tue Apr 28, 2026 8:56 pm ...unfortunately these crap these days should be
Debugged first by total disabling antivirus craps..

It has high probabilty...
Nor sure if I follow you here. You suggest that the app run slow on Android because of antivirus software?
I did try to set google protect to pause, but it is still is significantly slower when using GetDirecoryEntry vs GetAsset

Re: Very slow GetDirectoryEntry

Posted: Sat May 02, 2026 9:36 pm
by airsoftsoftwair
Very difficult to say what's going on without an example that I can test here. Have you got an MCVE?

Re: Very slow GetDirectoryEntry

Posted: Sun May 03, 2026 2:06 pm
by amyren
I did some troubleshooting along the way making this MCVE.
It looks like a combined case of things that provoke the slowdown.

First use this script on windows to create some files

Code: Select all

@DISPLAY {Title = "DirectoryEntry", ScaleMode = #SCALEMODE_AUTO, Orientation = #ORIENTATION_LANDSCAPE, FitScale = True, SmoothScale = True, HideTitleBar = True}

MakeDirectory("testfiles")
CreateBrush(1, 1920, 1080, #GRAY)
SaveBrush(1,  "testfiles/bgpic.png", {Format = #IMGFMT_PNG})
For i = 1 To 1000
	f$ = "testfiles/"..i..".png"
	CreateGradientBrush(i, 1200, 800, #LINEAR, GetRandomColor(), GetRandomColor())
	SaveBrush(i, f$, {Format = #IMGFMT_PNG})
Next
Here is the MCVE using directory entry:

Code: Select all

@DISPLAY {Title = "DirectoryEntry", ScaleMode = #SCALEMODE_AUTO, Orientation = #ORIENTATION_LANDSCAPE, FitScale = True, SmoothScale = True, HideTitleBar = True}
@REQUIRE "pdf"
@DIRECTORY 1, "testfiles"

LoadBGPic(1, GetDirectoryEntry(1, "bgpic.png"))
DisplayBGPic(1)	
For i = 1 To 100
	LoadBrush(i, GetDirectoryEntry(1, i..".png"))
Next 

Repeat
	DisplayBrush(Rnd(100)+1, Rnd(1720), Rnd(880))
	Wait(2)
Until IsLeftMouse() = True
Here is the same script, but using asset. That should load much faster on Android.

Code: Select all

@DISPLAY {Title = "DirectoryEntry", ScaleMode = #SCALEMODE_AUTO, Orientation = #ORIENTATION_LANDSCAPE, FitScale = True, SmoothScale = True, HideTitleBar = True}
@REQUIRE "pdf"

LoadBGPic(1, GetAsset("testfiles/bgpic.png"))
DisplayBGPic(1)	
For i = 1 To 100
	LoadBrush(i, GetAsset("testfiles/"..i..".png"))
Next 

Repeat
	DisplayBrush(Rnd(100)+1, Rnd(1720), Rnd(880))
	Wait(2)
Until IsLeftMouse() = True
Try the above first to see if you can replicate what I experience.

To complicate this even more, I did find that if replacing the pdf plugin with the old polybios plugin in this MCVE, then the slowdown is gone.
However, that does not help for my full script. There it is slow with both pdf and polybios unless I swicth to Asset.

Re: Very slow GetDirectoryEntry

Posted: Sun May 03, 2026 9:34 pm
by airsoftsoftwair
Thanks a lot for the detailed information and the MCVE! All the information you provided allows me to make an educated guess. I think this new feature introduced in version 2.0 of the PDF plugin is responsible for your problem:

Code: Select all

- New: The plugin can now also load PDF pages directly into brushes using @BRUSH and LoadBrush(); pass
  the "Page" user tag to @BRUSH or LoadBrush() to specify the number of the page to load; there is also
  a "Transparent" user tag which can be used to specify whether or not the plugin should fill the PDF
  page with a white background; if "Transparent" is FALSE (the default), the page will automatically
  be filled with a white background, otherwise it will be made transparent; finally, there is a user
  tag named "Password" which can be used to specify the password for encrypted PDFs
This means that all your LoadBrush() calls will first go through the PDF plugin which is probably slowing down things a lot. Polybios didn't have this feature so there was no slowdown. Also, the PDF plugin won't kick in when loading assets which is why there is no slowdown with assets either. So to fix the issue I think you just have to tell LoadBrush() to NOT use the PDF plugin, i.e. like this:

Code: Select all

LoadBGPic(1, GetDirectoryEntry(1, "bgpic.png"), {Loader = "inbuilt"})
DisplayBGPic(1)	
For i = 1 To 100
	LoadBrush(i, GetDirectoryEntry(1, i..".png"), {Loader = "inbuilt"})
Next
I haven't tested your code myself but judging from what you described I think that the new image loader adapter introduced in version 2.0 is the cause for your problem...

Re: Very slow GetDirectoryEntry

Posted: Mon May 04, 2026 1:28 am
by amyren
Thanks for your input.
That does make a huge difference for this particular MCVE, so your guess was correct.
I find that a bit odd though that it would use the pdf loader as default instead of the inbuilt one.

But this did not solve the issue completely for my full script, because I got that delay even when using polybios.

I did find another thing that made a huge difference for my script.
If I remove this line from the top of my script

Code: Select all

@FONT 1, "Times New Roman", 52,  {Engine = #FONTENGINE_INBUILT}
Then it loads about 5 seconds slower than when using GetAsset.
If I use the Asset method it loads in just a couple of seconds with out removing that line.

Also, if I add that font line into the MCVE above there will be a notable delay even for that small script.
Like this:

Code: Select all

@DISPLAY {Title = "DirectoryEntry", ScaleMode = #SCALEMODE_AUTO, Orientation = #ORIENTATION_LANDSCAPE, FitScale = True, SmoothScale = True, HideTitleBar = True}

@REQUIRE "pdf"

@DIRECTORY 1, "testfiles"
@FONT 1, "Times New Roman", 52,  {Engine = #FONTENGINE_INBUILT}

LoadBGPic(1, GetDirectoryEntry(1, "bgpic.png"), {Loader = "inbuilt"})
DisplayBGPic(1)	
For i = 1 To 100
	LoadBrush(i, GetDirectoryEntry(1, i..".png"), {Loader = "inbuilt"})
Next 

Repeat
	DisplayBrush(Rnd(100)+1, Rnd(1720), Rnd(880))
	Wait(2)
Until IsLeftMouse() = True

Re: Very slow GetDirectoryEntry

Posted: Sun May 10, 2026 6:42 pm
by airsoftsoftwair
amyren wrote: Mon May 04, 2026 1:28 am I did find another thing that made a huge difference for my script.
If I remove this line from the top of my script
@FONT 1, "Times New Roman", 52, {Engine = #FONTENGINE_INBUILT}
Then it loads about 5 seconds slower than when using GetAsset.
Hmm, don't understand this one. Do you mean it loads 5 seconds faster?

The thing with @FONT on Android sounds like this problem where we also have a slowdown as soon as the @FONT preprocessor command is used on Android or does it really load slower when @FONT is NOT present?

Re: Very slow GetDirectoryEntry

Posted: Mon May 11, 2026 7:52 am
by amyren
airsoftsoftwair wrote: Sun May 10, 2026 6:42 pm
amyren wrote: Mon May 04, 2026 1:28 am I did find another thing that made a huge difference for my script.
If I remove this line from the top of my script
@FONT 1, "Times New Roman", 52, {Engine = #FONTENGINE_INBUILT}
Then it loads about 5 seconds slower than when using GetAsset.
Hmm, don't understand this one. Do you mean it loads 5 seconds faster?

The thing with @FONT on Android sounds like this problem where we also have a slowdown as soon as the @FONT preprocessor command is used on Android or does it really load slower when @FONT is NOT present?

Code: Select all

I did find another thing that made a huge difference for my script.
If I remove this line from the top of my script
@FONT 1, "Times New Roman", 52, {Engine = #FONTENGINE_INBUILT}
The huge difference I was refering to above was my own porgram that was @FONT in combination with using @DIRECTORY. Removing @FONT does a huge difference if @DIRECTORY is also used.

This comment below was refering to the MCVE.

Code: Select all

Then it loads about 5 seconds slower than when using GetAsset.
If having both @FONT and @DIRECTORY in the MCVE it will load 5 seconds slower than if having
@FONT and use GetAsset.

It looks like the combination of @FONT and @DIRECTORY also cause a delay.

Re: Very slow GetDirectoryEntry

Posted: Sun May 17, 2026 9:50 pm
by airsoftsoftwair
Ok, thanks for the analysis. I'll debug this soon and get back.