-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TALRectangle, How optimize load Resource file ? #368
Comments
What you're experiencing is normal. When you set TALRectangle to load its Fill property from a large PNG file (around 1 MB), it results in a slow process due to bilinear interpolation—this is common in any software handling large images. To improve performance, you can force the form to create all its buffered bitmaps before the user starts scrolling. You can achieve this by using ALMakeBufDrawables(FakeContent). Take a look at the ALFmxControlsDemo in Alcinoe; I implemented the same solution there. |
ALMakeBufDrawables(FakeContent), work fine :) is "ALMakeBufDrawables" Thread safety ? i have make any test.. Why Mode-2 with 10 split is more slow of Mode-1 ? MODE 1 ALL IN ONE: 2.37 sec Setlength(tasks_multi, 1); tasks_multi[0] := TTask.Create (procedure () while not TTask.WaitForAll(tasks_multi, 100) do MODE 2 SPLIT 10 TASK : 2.38 sec Setlength(tasks_multi, 10); tasks_multi[0] := TTask.Create (procedure () tasks_multi[1] := TTask.Create (procedure () .... while not TTask.WaitForAll(tasks_multi, 100) do |
their is absolutely no advantage to do what you do, you create background thread and inside the background thread you do TThread.Synchronize that will ask the main thread to do the task! it's better to stay in the main thread and forget about TTask. also ALMakeBufDrawables is designed to work only in the main thread. |
Bench Update 1 TThread.CreateAnonymousThread : 2.2 sec 1 tasks_multi[0] := TTask.Created : 2.4 sec Array of Thread is VERY FAST. Array of Thread without .WAIT is near 0.1 sec ( i can open App Without LAG scroll, now ) Delphi 12.2 last test: |
you do badly, so call ALMakeBufDrawables from the main thread like in the alfmxcontrols sample. their is absolutely no gain to do like you do |
The problem might be in the management of TTasks in Delphi. |
their is no problem, you simply create a background task and from the background task you ask to execute the code in the main thread = absolutely 0 advantage, it's even more slow |
Hello, you can now try to use the last version of TALImage. in resourcename you can put an url and so the TALimage will download the image in the background and process it also in the background |
Hi @Zeus64 I'm testing last version of ALCI , i have open ALFmxControls example compiled for Android 64 and iPhone 64, but the image is not visible. https://.............landscape.jpg?raw=true i debugging mode -- No error visilble. All ok on Windows 64 ( landscape.jpg Image is visible) . I have try my example with TALImage with a my link and don't work on Android and iphone. Delphi 12.2 |
what you have in place of the image? can you show me a screenshot ? is it the same with this app : https://play.google.com/store/apps/details?id=io.magicfoundation.alcinoe.alfmxcontrolsdemo |
is possible add this (great) feature to TALRectangle ? |
something wrong somewhere :( normally when the image is downloading you must have a gray background and if the downloading failed you must have an error icon :( their is nothing in the android log ? |
look like something in your network replace the downloaded file https://github.com/MagicFoundation/Alcinoe/blob/master/Demos/ALFmxControls/_Design/landscape.jpg?raw=true with an empty blank image :( |
my img .jpg on Amazon S3 don't work |
i'm debugging... ALLog() no warning |
can you try again with the very last version i just commited ? and sent me the screenshoot ? |
get update. {*************} DEBUG ENTER HERE !!!!!!!! var LResourceDownloadExtData := TALImage.TResourceDownloadExtData(AExtData); |
class procedure TALImage.HandleResourceDownloadError(const AErrMessage: string; var AExtData: Tobject); IS NEVER CALLED. Your fix don't work. |
class procedure TALImage.HandleResourceDownloadSuccess(const AResponse: IHTTPResponse; var AContentStream: TMemoryStream; var AExtData: TObject); iDebugSize := AContentStream.size; HERE SIZE DOWNLOAD FILE IS CORRECT. |
|
On all my android device it's work good. On iphone i found the problem and just corrected it |
just commited a fix for iOS, can you try it again ? |
regarding android i try a several different phone, every work fine. |
Get only: Alcinoe.FMX.Graphics.pas on iPhone WORK FINE, now !! on my phone Samsung S24 Don't work. After TALImage.HandleResourceDownloadSuccess() You save the file on phone disk ? |
--- If the image is downloading then their is a gray background On S24 phone any time for 0.3 seconds a see a gray box, then make white clear. |
so something wrong on your phone, because you have only 3 options :
can you try to run the app without Internet to see if you see the little broken image ? |
-- an you try to run the app without Internet to see if you see the little broken image ? i have installed from Google Store your apk. Turn Off WIFI and Data , open .... no gray , no broken image, only ALL WHITE zone ( landscape.jpg ) i have open in Debug your project ALFmxControls on Android, without internet, there are any GPF / Error. |
It's really strange—it seems like your phone either downloaded an empty version of the image or is unable to render it. Could you try the following steps:
Let me know if you can see the image now. |
----Let me know if you can see the image now. Yes, work fine. now. ( but is load in old local mode, no download file from web ) |
That proves the problem is with your internet. :( Something on your S24 phone is replacing the downloaded image stream with an empty one. In
|
As I wrote above, inside "HandleResourceDownloadSuccess" the file is DOWNLOADED PERFECTLY. (Stream.size is correct) There are no problems in downloading, only in load / drawing inside the image. |
yes, but with this code, did it work ? :
I start to think that your OpenGL version in your s24 android phone is not working with background context / shared context. |
I’m now certain that the problem lies in the OpenGL context sharing on your phone, which isn’t working as expected. The bad news is that the Samsung S24 is quite an expensive phone, so it will be difficult for me to test it anytime soon. I’m fairly confident that if you do the following:
then it's will work |
Error in compiling: CreateBufDrawable is not a Class Visible [DCC Error] Alcinoe.FMX.Objects.pas(1750): E2250 There is no overloaded version of 'CreateBufDrawable' that can be called with these arguments |
so try instead this :
|
YES WORK FINE NOW !! on Samsung S24 Phone ,too :) TThread.synchronize(nil, |
No, it's not working fine. :( This test simply shows that on your phone, you can't create a texture in a background thread, which is not normal. We need to check whether this issue is specific to the S24 phone (possibly due to a bad OpenGL implementation) or if it's a broader problem. What is certain is that I need to be able to reproduce the issue, but on all the phones I have, I can't. :( I'll need to investigate further, but in the meantime, you can try using the SKIA canvas instead of the OpenGL canvas. I suspect that with the SKIA canvas, it will work in a background thread. |
I managed to find an S24 device and was able to reproduce the problem. I’ve already found a fix: it seems that on the S24, when creating a texture in a background thread, we must call glFinish before using it on the main thread. Could you update your Alcinoe repository to the latest commit and try again? |
Hi @Zeus64 I have download now last update and work fine on my Samsung S24 Ultra. i have tested on: Windows 32: OK Samsung Tablet 2024 TAB A9+ : OK Samsung S24 Ultra : OK iPhone 11 PRO Max : OK |
May add HTTP support to TALRectangle ? |
Perfect! :) |
Hi @Zeus64
Attach project:
acrylicscroll-sample-ALCINOE.zip
I'm testing the performance of Alcinoe project.
Thank you for your great project! :)
My Steps:
Download https://github.com/skia4delphi/acrylicscroll-sample
Test and Android device, on Samsung S24 Ultra the scroll is .. medium
i have converted the project at ALCINOE
Re Test on Android device
The image files .png are load in Resource mode, but the scroll is very slow for the first 5 seconds of scroll.
Is possibile opimize load of Resource PNG on TALRectangle ( TTask ? ) ?
Mauro Botta
Delphi 12.2
Last version of Alcinoe, Last version of Skia
The text was updated successfully, but these errors were encountered: