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
Image assets load is slow #70527
Comments
@mikeRozen also you might want to run your app with the flag |
@iapicca
regarding the image size the background image is 24KB AFAIK I cant run in release mode on the IOS simultor (correct me if I am wrong) |
@mikeRozen |
@iapicca |
not really, |
Hi @mikeRozen |
Without additional information, we are unfortunately not sure how to resolve this issue. Could everyone who still has this problem please file a new issue with the exact description of what happens, logs, and the output of |
My apologies for the late response @pedromassangocode , @TahaTesser , @iapicca
|
Please note after that the image get cached so opening a new screen with same background image will not have this delay. Its happens on the first time the image get loaded (which is the first screen and the first impression of the app) |
Hi @mikeRozen flutter doctor -v[✓] Flutter (Channel stable, 1.22.4, on Microsoft Windows [Version 10.0.19042.630], locale en-US)
• Flutter version 1.22.4 at C:\Code\flutter_stable
• Framework revision 1aafb3a8b9 (4 weeks ago), 2020-11-13 09:59:28 -0800
• Engine revision 2c956a31c0
• Dart version 2.10.4
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Code\sdk
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = C:\Code\sdk
• Java binary at: C:\Code\android-studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[!] Android Studio (version 4.1.0)
• Android Studio at C:\Code\android-studio
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[✓] VS Code (version 1.51.1)
• VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.17.0
[✓] Connected device (1 available)
• sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
! Doctor found issues in 1 category. |
@mikeRozen I believe you already know that, as the title of the issue is I'm not sure what slow means in this case, set upflutter channel master
flutter upgrade -f
flutter create img_bench
cd img_bench
mkdir assets
cd assets
wget https://flutter.dev/assets/homepage/carousel/slide_1-bg-4e2fcef9a7343692a5f7784d68241a786c57c79d55f0fe37e6b82a653d146b93.jpg
mv slide_1-bg-4e2fcef9a7343692a5f7784d68241a786c57c79d55f0fe37e6b82a653d146b93.jpg canyon.jpg
cd ..
echo -e '\n assets:\n - canyon.jpg' >> pubspec.yaml code samplereplace import 'package:flutter/material.dart';
void main() => runApp(
const MaterialApp(
home: Material(
child: Center(
child: MyImage(
imageProvider: AssetImage( 'canyon.jpg'),
),
),
),
),
);
/// code below edited from `https://api.flutter.dev/flutter/painting/ImageProvider-class.html#painting.ImageProvider.1`
/// comment removed, new comments above the edited lines
class MyImage extends StatefulWidget {
const MyImage({
Key key,
@required this.imageProvider,
}) : assert(imageProvider != null),
super(key: key);
final ImageProvider imageProvider;
@override
_MyImageState createState() => _MyImageState();
}
class _MyImageState extends State<MyImage> {
ImageStream _imageStream;
ImageInfo _imageInfo;
@override
void didChangeDependencies() {
super.didChangeDependencies();
_getImage();
}
@override
void didUpdateWidget(MyImage oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.imageProvider != oldWidget.imageProvider) _getImage();
}
void _getImage() {
/// added line for pseudo bencchmark
print('get image: ${DateTime.now()}');
final ImageStream oldImageStream = _imageStream;
_imageStream =
widget.imageProvider.resolve(createLocalImageConfiguration(context));
if (_imageStream.key != oldImageStream?.key) {
final ImageStreamListener listener = ImageStreamListener(_updateImage);
oldImageStream?.removeListener(listener);
_imageStream.addListener(listener);
}
}
void _updateImage(ImageInfo imageInfo, bool synchronousCall) {
setState(() {
/// added line for pseudo bencchmark
print('update image: ${DateTime.now()}');
_imageInfo = imageInfo;
});
}
@override
void dispose() {
_imageStream.removeListener(ImageStreamListener(_updateImage));
super.dispose();
}
@override
Widget build(BuildContext context) {
return RawImage(
image: _imageInfo?.image,
scale: _imageInfo?.scale ?? 1.0,
);
}
}
logsflutter run --release -v [ +4 ms] ✓ Built build/app/outputs/flutter-apk/app-release.apk (5.7MB).
[ +5 ms] executing: /home/francesco/Android/Sdk/build-tools/30.0.2/aapt dump xmltree /home/francesco/projects/imageprovider_bench/build/app/outputs/flutter-apk/app.apk AndroidManifest.xml
[ +8 ms] Exit code 0 from: /home/francesco/Android/Sdk/build-tools/30.0.2/aapt dump xmltree /home/francesco/projects/imageprovider_bench/build/app/outputs/flutter-apk/app.apk AndroidManifest.xml
[ ] N: android=http://schemas.android.com/apk/res/android
E: manifest (line=2)
A: android:versionCode(0x0101021b)=(type 0x10)0x1
A: android:versionName(0x0101021c)="1.0.0" (Raw: "1.0.0")
A: android:compileSdkVersion(0x01010572)=(type 0x10)0x1e
A: android:compileSdkVersionCodename(0x01010573)="11" (Raw: "11")
A: package="com.example.imageprovider_bench" (Raw: "com.example.imageprovider_bench")
A: platformBuildVersionCode=(type 0x10)0x1e
A: platformBuildVersionName=(type 0x10)0xb
E: uses-sdk (line=7)
A: android:minSdkVersion(0x0101020c)=(type 0x10)0x10
A: android:targetSdkVersion(0x01010270)=(type 0x10)0x1e
E: application (line=11)
A: android:label(0x01010001)="imageprovider_bench" (Raw: "imageprovider_bench")
A: android:icon(0x01010002)=@0x7f080000
A: android:appComponentFactory(0x0101057a)="androidx.core.app.CoreComponentFactory" (Raw: "androidx.core.app.CoreComponentFactory")
E: activity (line=15)
A: android:theme(0x01010000)=@0x7f0a0000
A: android:name(0x01010003)="com.example.imageprovider_bench.MainActivity" (Raw: "com.example.imageprovider_bench.MainActivity")
A: android:launchMode(0x0101001d)=(type 0x10)0x1
A: android:configChanges(0x0101001f)=(type 0x11)0x40003fb4
A: android:windowSoftInputMode(0x0101022b)=(type 0x11)0x10
A: android:hardwareAccelerated(0x010102d3)=(type 0x12)0xffffffff
E: meta-data (line=29)
A: android:name(0x01010003)="io.flutter.embedding.android.NormalTheme" (Raw: "io.flutter.embedding.android.NormalTheme")
A: android:resource(0x01010025)=@0x7f0a0001
E: meta-data (line=39)
A: android:name(0x01010003)="io.flutter.embedding.android.SplashScreenDrawable" (Raw: "io.flutter.embedding.android.SplashScreenDrawable")
A: android:resource(0x01010025)=@0x7f040000
E: intent-filter (line=43)
E: action (line=44)
A: android:name(0x01010003)="android.intent.action.MAIN" (Raw: "android.intent.action.MAIN")
E: category (line=46)
A: android:name(0x01010003)="android.intent.category.LAUNCHER" (Raw: "android.intent.category.LAUNCHER")
E: meta-data (line=53)
A: android:name(0x01010003)="flutterEmbedding" (Raw: "flutterEmbedding")
A: android:value(0x01010024)=(type 0x10)0x2
[ +2 ms] Stopping app 'app.apk' on Pixel 3a.
[ +1 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell am force-stop com.example.imageprovider_bench
[ +128 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell pm list packages com.example.imageprovider_bench
[ +106 ms] package:com.example.imageprovider_bench
[ +5 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell cat /data/local/tmp/sky.com.example.imageprovider_bench.sha1
[ +87 ms] 5cf835028649157d90a0fae0dc9be0ba11ab6c84
[ +1 ms] Installing APK.
[ +4 ms] Installing build/app/outputs/flutter-apk/app.apk...
[ +1 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C install -t -r /home/francesco/projects/imageprovider_bench/build/app/outputs/flutter-apk/app.apk
[+1578 ms] Performing Streamed Install
Success
[ +3 ms] Installing build/app/outputs/flutter-apk/app.apk... (completed in 1,579ms)
[ +3 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell echo -n 2532e7e0a388f0e5f153ce520991e2da92c00625 > /data/local/tmp/sky.com.example.imageprovider_bench.sha1
[ +42 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell am start -a android.intent.action.RUN -f 0x20000000 --ez enable-background-compilation true --ez
enable-dart-profiling true com.example.imageprovider_bench/com.example.imageprovider_bench.MainActivity
[ +72 ms] Starting: Intent { act=android.intent.action.RUN flg=0x20000000 cmp=com.example.imageprovider_bench/.MainActivity (has extras) }
[ +2 ms] Application running.
[ +3 ms] Flutter run key commands.
[ +3 ms] h Repeat this help message.
[ +1 ms] c Clear the screen
[ ] q Quit (terminate the application on the device).
[ +493 ms] I/flutter (17301): get image: 2020-12-10 16:39:42.015517
[ +55 ms] I/flutter (17301): update image: 2020-12-10 16:39:42.071453
results about 55 millisecondsflutter clean
flutter run -v [ +4 ms] Installing build/app/outputs/flutter-apk/app.apk...
[ +1 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C install -t -r /home/francesco/projects/imageprovider_bench/build/app/outputs/flutter-apk/app.apk
[+4778 ms] Performing Streamed Install
Success
[ ] Installing build/app/outputs/flutter-apk/app.apk... (completed in 4.8s)
[ +1 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell echo -n a8aa09b27150753efb8b25b03c0438a863d63531 > /data/local/tmp/sky.com.example.imageprovider_bench.sha1
[ +37 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell -x logcat -v time -t 1
[ +46 ms] --------- beginning of main
12-10 16:42:20.058 I/Finsky (15319): [665] hck.a(3): Cancelled 0 ongoing asset module downloads for package com.example.imageprovider_bench due to a concurrent app update.
[ +31 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell am start -a android.intent.action.RUN -f 0x20000000 --ez enable-background-compilation true --ez
enable-dart-profiling true --ez enable-checked-mode true --ez verify-entry-points true com.example.imageprovider_bench/com.example.imageprovider_bench.MainActivity
[ +82 ms] Starting: Intent { act=android.intent.action.RUN flg=0x20000000 cmp=com.example.imageprovider_bench/.MainActivity (has extras) }
[ +1 ms] Waiting for observatory port to be available...
[+1179 ms] Observatory URL on device: http://127.0.0.1:38473/X1GJQpK7ibw=/
[ +4 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C forward tcp:0 tcp:38473
[ +18 ms] 38853
[ ] Forwarded host port 38853 to device port 38473 for Observatory
[ +7 ms] Caching compiled dill
[ +137 ms] Connecting to service protocol: http://127.0.0.1:38853/X1GJQpK7ibw=/
[ +2 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:38853/X1GJQpK7ibw=/.
[ +710 ms] DDS is listening at http://127.0.0.1:41781/1j02Gn7D4zg=/.
[ +64 ms] Successfully connected to service protocol: http://127.0.0.1:38853/X1GJQpK7ibw=/
[ +23 ms] DevFS: Creating new filesystem on the device (null)
[ +37 ms] DevFS: Created new filesystem on the device (file:///data/user/0/com.example.imageprovider_bench/code_cache/imageprovider_benchNDAONF/imageprovider_bench/)
[ +10 ms] Updating assets
[ +118 ms] Syncing files to device Pixel 3a...
[ +1 ms] <- reset
[ ] Compiling dart to kernel with 0 updated files
[ +1 ms] <- recompile package:imageprovider_bench/main.dart 72588266-b6a0-4415-a0b5-40f2977df76e
[ ] <- 72588266-b6a0-4415-a0b5-40f2977df76e
[ +105 ms] Updating files.
[ ] DevFS: Sync finished
[ ] Syncing files to device Pixel 3a... (completed in 110ms)
[ ] Synced 0.0MB.
[ ] <- accept
[ +18 ms] Connected to _flutterView/0x77fe15de60.
[ +1 ms] Flutter run key commands.
[ +1 ms] r Hot reload. 🔥🔥🔥
[ ] R Hot restart.
[ ] h Repeat this help message.
[ ] d Detach (terminate "flutter run" but leave application running).
[ ] c Clear the screen
[ ] q Quit (terminate the application on the device).
[ ] An Observatory debugger and profiler on Pixel 3a is available at: http://127.0.0.1:41781/1j02Gn7D4zg=/
[ ] Running with unsound null safety
[ ] For more information see https://dart.dev/null-safety/unsound-null-safety
[ +201 ms] I/flutter (17808): get image: 2020-12-10 16:42:22.843361
[ +427 ms] I/flutter (17808): update image: 2020-12-10 16:42:23.278589
results about 435 millisecondsdoctor[✓] Flutter (Channel master, 1.25.0-5.0.pre.141, on Linux, locale en_US.UTF-8)
• Flutter version 1.25.0-5.0.pre.141 at /home/francesco/snap/flutter/common/flutter
• Framework revision 36bed2b4c3 (14 hours ago), 2020-12-09 20:13:04 -0500
• Engine revision 8518a5bbe6
• Dart version 2.12.0 (build 2.12.0-135.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /home/francesco/Android/Sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: /snap/android-studio/current/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
• cmake version 3.10.2
• ninja version 1.8.2
• pkg-config version 0.29.1
[✓] Android Studio
• Android Studio at /snap/android-studio/current/android-studio
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = /snap/android-studio/current/android-studio
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] Connected device (3 available)
• Pixel 3a (mobile) • 965AY0WP5C • android-arm64 • Android 11 (API 30)
• Linux (desktop) • linux • linux-x64 • Linux
• Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88
• No issues found!
what result are you getting from this pseudo benchmark? |
First of all, thanks a lot for your help. Sample code
flutter doctor
I didn't try it in release mode, from your logs I see that it's almost 9x faster so I tend to believe we won't feel it in production (hope so as my image 8x smaller than yours ). Thanks again. |
@TahaTesser attaching video with @iapicca code |
the reason why I posted a comparison between release and debug
as mentioned above, this is not how the framework is designed; lastly, something might be wrong in the logs, I don't see the print for /Users/user_name/AndroidStudioProjects/flutter_app_image_load/build/ios/iphonesimulator/Runner.app
[ +939 ms] executing: /usr/bin/plutil -convert json -o - /Users/user_name/AndroidStudioProjects/flutter_app_image_load/build/ios/iphonesimulator/Runner.app/Info.plist
[ +7 ms] Exit code 0 from: /usr/bin/plutil -convert json -o -
/Users/user_name/AndroidStudioProjects/flutter_app_image_load/build/ios/iphonesimulator/Runner.app/Info.plist
[ ]
{"CFBundleName":"flutter_app_image_load","DTXcode":"1120","DTSDKName":"iphonesimulator13.2","UILaunchStoryboardName":"LaunchScreen","CFBundleIcons~ipad":{"CFBundlePrimaryIco
n":{"CFBundleIconFiles":["AppIcon20x20","AppIcon29x29","AppIcon40x40","AppIcon60x60","AppIcon76x76","AppIcon83.5x83.5"],"CFBundleIconName":"AppIcon"}},"DTSDKBuild":"17B102",
"CFBundleDevelopmentRegion":"en","CFBundleVersion":"1","BuildMachineOSBuild":"19B88","DTPlatformName":"iphonesimulator","CFBundlePackageType":"APPL","UIMainStoryboardFile":"
Main","CFBundleSupportedPlatforms":["iPhoneSimulator"],"CFBundleShortVersionString":"1.0.0","CFBundleInfoDictionaryVersion":"6.0","CFBundleExecutable":"Runner","DTCompiler":
"com.apple.compilers.llvm.clang.1_0","UISupportedInterfaceOrientations~ipad":["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortraitUpsideDown","UIInterfaceOrienta
tionLandscapeLeft","UIInterfaceOrientationLandscapeRight"],"MinimumOSVersion":"9.0","CFBundleIdentifier":"com.flutterAppImageLoad","UIDeviceFamily":[1,2],"DTPlatformVersion"
:"13.2","CFBundleSignature":"????","CFBundleIcons":{"CFBundlePrimaryIcon":{"CFBundleIconFiles":["AppIcon20x20","AppIcon29x29","AppIcon40x40","AppIcon60x60"],"CFBundleIconNam
e":"AppIcon"}},"DTXcodeBuild":"11B500","LSRequiresIPhoneOS":true,"UISupportedInterfaceOrientations":["UIInterfaceOrientationPortrait","UIInterfaceOrientationLandscapeLeft","
UIInterfaceOrientationLandscapeRight"],"UIViewControllerBasedStatusBarAppearance":false,"NSBonjourServices":["_dartobservatory._tcp"],"DTPlatformBuild":"17B102","NSLocalNetw
orkUsageDescription":"Allow Flutter tools on your computer to connect and debug your application. This prompt will not appear on release builds."}
[ +3 ms] executing: xcrun simctl launch C42DDFF8-071E-48C7-9D43-169E58C63215 com.flutterAppImageLoad --enable-dart-profiling --enable-checked-mode --verify-entry-points
--observatory-port=0
[ +342 ms] com.flutterAppImageLoad: 30429
[ ] Waiting for observatory port to be available...
[+2076 ms] Observatory URL on device: http://127.0.0.1:49416/scAyZt5rzgs=/
[ +15 ms] Caching compiled dill
[ +218 ms] Connecting to service protocol: http://127.0.0.1:49416/scAyZt5rzgs=/
[ +4 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:49416/scAyZt5rzgs=/.
[ +236 ms] DDS is listening at http://127.0.0.1:49425/M4KbxYrcQ_s=/.
[ +96 ms] Successfully connected to service protocol: http://127.0.0.1:49416/scAyZt5rzgs=/
[ +13 ms] DevFS: Creating new filesystem on the device (null)
[ +14 ms] DevFS: Created new filesystem on the device
(file:///Users/user_name/Library/Developer/CoreSimulator/Devices/C42DDFF8-071E-48C7-9D43-169E58C63215/data/Containers/Data/Application/A90696DE-46E0-4B55-8B27-82264A2
DFE2F/tmp/flutter_app_image_loadoJLFdY/flutter_app_image_load/)
[ +3 ms] Updating assets
[ +108 ms] Manifest contained wildcard assets. Inserting missing file into build graph to force rerun. for more information see #56466.
[ +6 ms] Syncing files to device iPhone 11 Pro Max...
[ +2 ms] <- reset
[ ] Compiling dart to kernel with 0 updated files
[ +4 ms] <- recompile package:flutter_app_image_load/main.dart c582ae0c-d265-43c8-967c-4e4fb8ed2cb1
[ ] <- c582ae0c-d265-43c8-967c-4e4fb8ed2cb1
[ +1 ms] flutter: get image: 2020-12-10 22:23:55.545693
[ +120 ms] Updating files.
[ ] DevFS: Sync finished
[ ] Syncing files to device iPhone 11 Pro Max... (completed in 129ms)
[ ] Synced 0.0MB.
[ +1 ms] <- accept
[ +6 ms] Connected to _flutterView/0x7fb385029a20.
[ +1 ms] Flutter run key commands.
[ +1 ms] r Hot reload. 🔥🔥🔥
[ ] R Hot restart.
[ ] h Repeat this help message.
[ ] d Detach (terminate "flutter run" but leave application running).
[ ] c Clear the screen
[ ] q Quit (terminate the application on the device).
[ ] An Observatory debugger and profiler on iPhone 11 Pro Max is available at: http://127.0.0.1:49425/M4KbxYrcQ_s=/
[ ] Running with unsound null safety
[ ] For more information see https://dart.dev/null-safety/unsound-null-safety
[ +235 ms] flutter: update image: 2020-12-10 22:23:55.966705 |
@iapicca |
@mikeRozen |
This issue is affecting me too. All other widgets load before the image does on the first screen, ruining the smoothness the user should experience when opening the app |
Could everyone who still has this problem please file a new issue with the exact description of what happens, logs, and the output of |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Hi,
My local image assets loading is slow, it hapens on the first screen/page on IOS simulator (I didnt tried on other pages or on Android ). I tried all possible solution on stack (like caching etc with no help). I think that currently its unpossible to run in production mode in simulator
Steps to Reproduce
Expected results: The images should appear as the screen loads
Actual results: Images appear with short delay
Logs
logs_flutter_doctor.txt
logs_flutter_analyze.txt
logs_verboose.txt
I also tried to use caching
Thanks for your help.
The text was updated successfully, but these errors were encountered: