Repository navigation
Long list variable slowing performance #80176
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: animationAnimation APIsAnimation APIsc: performanceRelates to speed or footprint issues (see "perf:" labels)Relates to speed or footprint issues (see "perf:" labels)f: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 2.10Found to occur in 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13Found to occur in 2.13frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
When I try to use a list of 14216 maps, this widget freezes for a few seconds during initialization:
class Slow extends StatefulWidget {
Slow({Key key}) : super(key: key);
@override
_SlowState createState() => _SlowState();
}
class _SlowState extends State<Slow> {
List _list = [
{
"code": "110000000",
"region": "11",
"district": "0",
"locality_center": "0",
"locality": "0",
"ru_name": "Акмолинская область",
"kk_name": "Ақмола облысы"
},
// 14215 maps
];
@override
Widget build(BuildContext context) {
print('it takes a few seconds before this message is printed in terminal');
print(_list.length);
return Container();
}
}
Is there a better way of storing and using huge lists in flutter?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: animationAnimation APIsAnimation APIsc: performanceRelates to speed or footprint issues (see "perf:" labels)Relates to speed or footprint issues (see "perf:" labels)f: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 2.10Found to occur in 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13Found to occur in 2.13frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Activity
ta9ki commentedon Apr 10, 2021
Вы желаете пользователю показывать такие длинные списки? если нет, то используйте SQLITE или HIVE
hamdikahloun commentedon Apr 10, 2021
Hi @nausharipov
Can you please provide your
flutter doctor -v, yourflutter run --verboseand a minimal complete reproducible code sample?Thank you
See: Work with long lists
iapicca commentedon Apr 11, 2021
@hamdikahloun
I do not experience the behavior @nausharipov is reporting
[ +477 ms] I/flutter ( 9193): 15000but if you try to animate to bottom (press the
fab) the app indeed freezesjust watch the
gifuntil the endcode sample
note
some steps in the sample are "unnecessary" but try to reproduce a real world parsing and and serialization
flutter run --release -v
[ +112 ms] ✓ Built build/app/outputs/flutter-apk/app-release.apk (6.0MB). [ +4 ms] executing: /home/francesco/Android/Sdk/build-tools/30.0.2/aapt dump xmltree /home/francesco/projects/issue/build/app/outputs/flutter-apk/app.apk AndroidManifest.xml [ +7 ms] Exit code 0 from: /home/francesco/Android/Sdk/build-tools/30.0.2/aapt dump xmltree /home/francesco/projects/issue/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.issue" (Raw: "com.example.issue") 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)="issue" (Raw: "issue") A: android:icon(0x01010002)=@0x7f080000 A: android:appComponentFactory(0x0101057a)="androidx.core.app.Core ComponentFactory" (Raw: "androidx.core.app.CoreComponentFactory") E: activity (line=15) A: android:theme(0x01010000)=@0x7f0a0000 A: android:name(0x01010003)="com.example.issue.MainActivity" (Raw: "com.example.issue.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.Norm alTheme" (Raw: "io.flutter.embedding.android.NormalTheme") A: android:resource(0x01010025)=@0x7f0a0001 E: meta-data (line=39) A: android:name(0x01010003)="io.flutter.embedding.android.Spla shScreenDrawable" (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.LAUNCHE R" (Raw: "android.intent.category.LAUNCHER") E: meta-data (line=53) A: android:name(0x01010003)="flutterEmbedding" (Raw: "flutterEmbedding") A: android:value(0x01010024)=(type 0x10)0x2 [ +3 ms] Stopping app 'app.apk' on Pixel 3a. [ ] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell am force-stop com.example.issue [ +125 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell pm list packages com.example.issue [ +104 ms] package:com.example.issue [ +5 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell cat /data/local/tmp/sky.com.example.issue.sha1 [ +94 ms] 900c5ff46a5986d2339e084e00a4e03d07ccedf6 [ +2 ms] Latest build already installed. [ +2 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.issue/com.example.issue.MainActivity [ +109 ms] Starting: Intent { act=android.intent.action.RUN flg=0x20000000 cmp=com.example.issue/.MainActivity (has extras) } [ +6 ms] Application running. [ +9 ms] Flutter run key commands. [ +5 ms] h Repeat this help message. [ +1 ms] c Clear the screen [ +1 ms] q Quit (terminate the application on the device). [ +477 ms] I/flutter ( 9193): 15000 [ +1 ms] I/flutter ( 9193): code 0 [ +4 ms] I/flutter ( 9193): code 1 [ ] I/flutter ( 9193): code 2 [ +1 ms] I/flutter ( 9193): code 3 [ +2 ms] I/flutter ( 9193): code 4 [ ] I/flutter ( 9193): code 5 [ +1 ms] I/flutter ( 9193): code 6 [ +1 ms] I/flutter ( 9193): code 7 [ +1 ms] I/flutter ( 9193): code 8 [ +1 ms] I/flutter ( 9193): code 9 [ +1 ms] I/flutter ( 9193): code 10 [ +1 ms] I/flutter ( 9193): code 11 [ ] I/flutter ( 9193): code 12 [ +1 ms] I/flutter ( 9193): code 13 [ +1 ms] I/flutter ( 9193): code 14 [ +1 ms] I/flutter ( 9193): code 15 [ +1 ms] I/flutter ( 9193): code 16 [ ] I/flutter ( 9193): code 17 [ +2 ms] I/flutter ( 9193): code 18 [ ] I/flutter ( 9193): code 19 [ +2 ms] I/flutter ( 9193): code 20 [ ] I/flutter ( 9193): code 21 [ ] I/flutter ( 9193): code 22 [ +1 ms] I/flutter ( 9193): code 23 [ ] I/flutter ( 9193): code 24 [ +2 ms] I/flutter ( 9193): code 25 [ +1 ms] I/flutter ( 9193): code 26 [ +1 ms] I/flutter ( 9193): code 27 [ ] I/flutter ( 9193): code 28 [ +1 ms] I/flutter ( 9193): code 29 [ +1 ms] I/flutter ( 9193): code 30 [ +1 ms] I/flutter ( 9193): code 31 [ +1 ms] I/flutter ( 9193): code 32 [ +2 ms] I/flutter ( 9193): code 33 [ ] I/flutter ( 9193): code 34 [ ] I/flutter ( 9193): code 35 [ ] I/flutter ( 9193): code 36 [ +1 ms] I/flutter ( 9193): code 37 [ +1 ms] I/flutter ( 9193): code 38 [ +1 ms] I/flutter ( 9193): code 39 [ ] I/flutter ( 9193): code 40 [ ] I/flutter ( 9193): code 41 [ ] I/flutter ( 9193): code 42 [ ] I/flutter ( 9193): code 43 [ +1 ms] I/flutter ( 9193): code 44 [ +1 ms] I/flutter ( 9193): code 45 [ +2 ms] I/flutter ( 9193): code 46 [ +1 ms] I/flutter ( 9193): code 47 [ +1 ms] I/flutter ( 9193): code 48 [ ] I/flutter ( 9193): code 49 [ ] I/flutter ( 9193): code 50 [ ] I/flutter ( 9193): code 51 [ ] I/flutter ( 9193): code 52 [ +1 ms] I/flutter ( 9193): code 53 [ +1 ms] I/flutter ( 9193): code 54 [ +1 ms] I/flutter ( 9193): code 55 [ ] I/flutter ( 9193): code 56 [ +1 ms] I/flutter ( 9193): code 57 [ +1 ms] I/flutter ( 9193): code 58 [ +1 ms] I/flutter ( 9193): code 59 [ +1 ms] I/flutter ( 9193): code 60 [ +1 ms] I/flutter ( 9193): code 61doctor
@ta9ki
in some case it might be useful to cache a big chunk of data rather query every single element of the list,
edit
assigning to the
animationadurationequal to 16333 microseconds (roughly a frame at 60 fps) times the number of itemsthe behavior is less bad, but still bad...
there's a lost second between the
expectedand theactual durationcode sample
flutter run --release -v
[ +124 ms] ✓ Built build/app/outputs/flutter-apk/app-release.apk (6.1MB). [ +3 ms] executing: /home/francesco/Android/Sdk/build-tools/30.0.2/aapt dump xmltree /home/francesco/projects/issue/build/app/outputs/flutter-apk/app.apk AndroidManifest.xml [ +7 ms] Exit code 0 from: /home/francesco/Android/Sdk/build-tools/30.0.2/aapt dump xmltree /home/francesco/projects/issue/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.issue" (Raw: "com.example.issue") 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)="issue" (Raw: "issue") 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.issue.MainActivity" (Raw: "com.example.issue.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 [ +1 ms] Stopping app 'app.apk' on Pixel 3a. [ ] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell am force-stop com.example.issue [ +117 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell pm list packages com.example.issue [ +109 ms] package:com.example.issue [ +5 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell cat /data/local/tmp/sky.com.example.issue.sha1 [ +71 ms] 7ecb83a57d40c8f2995a091398a620137592737a [ +1 ms] Installing APK. [ +3 ms] Installing build/app/outputs/flutter-apk/app.apk... [ ] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C install -t -r /home/francesco/projects/issue/build/app/outputs/flutter-apk/app.apk [+1079 ms] Performing Streamed Install Success [ +4 ms] Installing build/app/outputs/flutter-apk/app.apk... (completed in 1,080ms) [ +3 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell echo -n cf75a6fe5f108a28e47116686215b299195d6ece > /data/local/tmp/sky.com.example.issue.sha1 [ +36 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.issue/com.example.issue.MainActivity [ +87 ms] Starting: Intent { act=android.intent.action.RUN flg=0x20000000 cmp=com.example.issue/.MainActivity (has extras) } [ +5 ms] Application running. [ +6 ms] Flutter run key commands. [ +4 ms] h Repeat this help message. [ +1 ms] c Clear the screen [ ] q Quit (terminate the application on the device). [ +608 ms] I/flutter (11689): 15000 [+12955 ms] I/flutter (11689): expected duration: 244 [+245043 ms] I/flutter (11689): actual duration: 245 [+14296 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell am force-stop com.example.issue [ +164 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C shell am force-stop com.example.issue [ +80 ms] Application finished. [ +20 ms] "flutter run" took 305,723ms. [ +266 ms] ensureAnalyticsSent: 254ms [ +5 ms] Running shutdown hooks [ +1 ms] Shutdown hooks complete [ +1 ms] exiting with code 0video (about 4 minutes)
nausharipov commentedon Apr 11, 2021
@hamdikahloun the code sample @iapicca sent is accurate. Here's my flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.4, on macOS 11.2.3 20D91 darwin-arm, locale en)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.55.1)
[✓] Connected device (2 available)
• No issues found!
agod777 commentedon Apr 11, 2021
darshankawar commentedon Apr 12, 2021
flutter doctor -v
exaby73 commentedon May 11, 2022
This issue still persists on stable and master as of writing this. Refer to @iapicca's comment here for the code samples I used for this test. The outcome is the same
flutter doctor -viapicca commentedon Aug 8, 2024
I'm observing some strange behavior from `ScrollController, I opened an issue to investigate
github-actions commentedon Aug 22, 2024
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
flutter doctor -vand a minimal reproduction of the issue.