How to handle searching Large Lists in Flutter?Logging large strings from FlutterListview filter search in FlutterGoogle Search in Flutterhandle special characters in FlutterFlutter/Dart number handling abilityHandling multitouch in flutterFlutter large project size on githubhow to update page state after Navigator.pop() from an alert boxFlutter - How to query search item in ListSearch with using GraphQLProvider in Flutter

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

Is it correct to write "is not focus on"?

Valid Badminton Score?

What to do with wrong results in talks?

The plural of 'stomach"

What would happen if the UK refused to take part in EU Parliamentary elections?

Why does John Bercow say “unlock” after reading out the results of a vote?

Hide Select Output from T-SQL

Is a roofing delivery truck likely to crack my driveway slab?

Why are on-board computers allowed to change controls without notifying the pilots?

is this a spam?

There is only s̶i̶x̶t̶y one place he can be

Your magic is very sketchy

Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

Is expanding the research of a group into machine learning as a PhD student risky?

Trouble understanding overseas colleagues

What is the opposite of 'gravitas'?

Is it okay / does it make sense for another player to join a running game of Munchkin?

Was the picture area of a CRT a parallelogram (instead of a true rectangle)?

Is this Spell Mimic feat balanced?

How do I rename a LINUX host without needing to reboot for the rename to take effect?

Bash method for viewing beginning and end of file

Is there any easy technique written in Bhagavad GITA to control lust?



How to handle searching Large Lists in Flutter?


Logging large strings from FlutterListview filter search in FlutterGoogle Search in Flutterhandle special characters in FlutterFlutter/Dart number handling abilityHandling multitouch in flutterFlutter large project size on githubhow to update page state after Navigator.pop() from an alert boxFlutter - How to query search item in ListSearch with using GraphQLProvider in Flutter













1















I want to ask how I should handle a large list in Flutter. My app gets super slow when I am at a data item that is really deep in the list which I am searching. My list is 70,000+ objects of a data structure large.



The following is how I am "Searching" the list.



Future<Iterable<SomeDataStruct>> _getAllData() async 
return allData.where((a) => (a.dataTitle.toLowerCase().contains(querySearch.toLowerCase().trim())));



Building the list using a ListView.builder inside of a FutureBuilder.



When I search and a result or results from deep inside the list are populated the app is extremely slow to the point where I click a list item and it takes few seconds before it does its onTap. And if I need to change the search query it takes time for the soft keyboard to come back up after I click on the TextField.



Where am I making a mistake or handling this wrong, what should I do to have my huge list searchable without making app unbearable.



EDIT:
How I made it not slow down the app after change to code. Is this correct?



String tempQuery;
List<SomeDataStruct> searchResults = [];
Future<List<SomeDataStruct>> _getAllData() async
if(querySearch!=tempQuery)
tempQuery = querySearch;
searchResults = allData.where((a) => (a.dataTitle.toLowerCase().contains(querySearch.toLowerCase().trim()))).toList();

return searchResults;










share|improve this question
























  • I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List and then adding .toList behind the return.

    – punjabi4life
    Mar 9 at 5:38
















1















I want to ask how I should handle a large list in Flutter. My app gets super slow when I am at a data item that is really deep in the list which I am searching. My list is 70,000+ objects of a data structure large.



The following is how I am "Searching" the list.



Future<Iterable<SomeDataStruct>> _getAllData() async 
return allData.where((a) => (a.dataTitle.toLowerCase().contains(querySearch.toLowerCase().trim())));



Building the list using a ListView.builder inside of a FutureBuilder.



When I search and a result or results from deep inside the list are populated the app is extremely slow to the point where I click a list item and it takes few seconds before it does its onTap. And if I need to change the search query it takes time for the soft keyboard to come back up after I click on the TextField.



Where am I making a mistake or handling this wrong, what should I do to have my huge list searchable without making app unbearable.



EDIT:
How I made it not slow down the app after change to code. Is this correct?



String tempQuery;
List<SomeDataStruct> searchResults = [];
Future<List<SomeDataStruct>> _getAllData() async
if(querySearch!=tempQuery)
tempQuery = querySearch;
searchResults = allData.where((a) => (a.dataTitle.toLowerCase().contains(querySearch.toLowerCase().trim()))).toList();

return searchResults;










share|improve this question
























  • I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List and then adding .toList behind the return.

    – punjabi4life
    Mar 9 at 5:38














1












1








1








I want to ask how I should handle a large list in Flutter. My app gets super slow when I am at a data item that is really deep in the list which I am searching. My list is 70,000+ objects of a data structure large.



The following is how I am "Searching" the list.



Future<Iterable<SomeDataStruct>> _getAllData() async 
return allData.where((a) => (a.dataTitle.toLowerCase().contains(querySearch.toLowerCase().trim())));



Building the list using a ListView.builder inside of a FutureBuilder.



When I search and a result or results from deep inside the list are populated the app is extremely slow to the point where I click a list item and it takes few seconds before it does its onTap. And if I need to change the search query it takes time for the soft keyboard to come back up after I click on the TextField.



Where am I making a mistake or handling this wrong, what should I do to have my huge list searchable without making app unbearable.



EDIT:
How I made it not slow down the app after change to code. Is this correct?



String tempQuery;
List<SomeDataStruct> searchResults = [];
Future<List<SomeDataStruct>> _getAllData() async
if(querySearch!=tempQuery)
tempQuery = querySearch;
searchResults = allData.where((a) => (a.dataTitle.toLowerCase().contains(querySearch.toLowerCase().trim()))).toList();

return searchResults;










share|improve this question
















I want to ask how I should handle a large list in Flutter. My app gets super slow when I am at a data item that is really deep in the list which I am searching. My list is 70,000+ objects of a data structure large.



The following is how I am "Searching" the list.



Future<Iterable<SomeDataStruct>> _getAllData() async 
return allData.where((a) => (a.dataTitle.toLowerCase().contains(querySearch.toLowerCase().trim())));



Building the list using a ListView.builder inside of a FutureBuilder.



When I search and a result or results from deep inside the list are populated the app is extremely slow to the point where I click a list item and it takes few seconds before it does its onTap. And if I need to change the search query it takes time for the soft keyboard to come back up after I click on the TextField.



Where am I making a mistake or handling this wrong, what should I do to have my huge list searchable without making app unbearable.



EDIT:
How I made it not slow down the app after change to code. Is this correct?



String tempQuery;
List<SomeDataStruct> searchResults = [];
Future<List<SomeDataStruct>> _getAllData() async
if(querySearch!=tempQuery)
tempQuery = querySearch;
searchResults = allData.where((a) => (a.dataTitle.toLowerCase().contains(querySearch.toLowerCase().trim()))).toList();

return searchResults;







dart flutter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 10:34







punjabi4life

















asked Mar 7 at 11:51









punjabi4lifepunjabi4life

306




306












  • I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List and then adding .toList behind the return.

    – punjabi4life
    Mar 9 at 5:38


















  • I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List and then adding .toList behind the return.

    – punjabi4life
    Mar 9 at 5:38

















I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List and then adding .toList behind the return.

– punjabi4life
Mar 9 at 5:38






I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List and then adding .toList behind the return.

– punjabi4life
Mar 9 at 5:38













2 Answers
2






active

oldest

votes


















1














Contains is expensive



Contains-queries are expensive, because every entry needs to be checked at every position (up to value.length - searchTerm.length) if the search term can be found.



Limiting search support to the beginning of the string would improve performance a lot already. In addition you could create helper data-structures where the whole list of values is split into parts with the same character at the beginning. If the chunks are still too big another level could be added for the 2nd character. The lookup would be fast because there are only a limited number of characters.



Using a database might take off some programming work (maintaining indexes). A database like SQLite could be used with indexes specialized to your kind of queries.



Split into smaller chunks of work to allow the framework to do its work



If you can't limit to "beginning of string"-search, you could still split the data structure into smaller chunks and invoke search for each chunk async. This way the UI gets "some air to breath" to re-render the UI before the next chunk is searched. The search result would be updated incrementally.



Move work off the UI thread



Another way would be to start up another isolate and do the search there. Another isolate can run on another CPU (core) and therefore would not block the UI thread when searching. This way it wouldn't be necessary to split into chunks. It might still be advantageous though to incrementally update the UI instead of keeping the user waiting until the whole search result becomes available.



See also



  • https://api.dartlang.org/stable/2.2.0/dart-isolate/dart-isolate-library.html

  • https://pub.dartlang.org/packages/isolate

  • https://codingwithjoe.com/dart-fundamentals-isolates/

Caching



It might also help improve performance to keep search results in memory. For example if the user enters foo and then presses backspace then you could reuse the search result for fo that you previously calculated already, but that only helps in some cases.



Measuring



Another important point of course is to do benchmarking. Whatever you try to improve performance, create benchmarks to learn what measures have what effect and if it's worth it. You'll learn a lot about your scenario, your data, Dart, ..., and this will allow you to make good decisions.






share|improve this answer

























  • After trying to move the work of the UI thread and not getting the results I I needed, the other methods did not fit my needs. I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List<SomeDataStruct> and then adding .toList behind the return.

    – punjabi4life
    Mar 9 at 5:40











  • Interesting. Can't imagine why this helps.

    – Günter Zöchbauer
    Mar 9 at 8:51











  • Yeah, it works now. App doesn't slow down like it would before. I have made an edit to my post showing the new code.

    – punjabi4life
    Mar 9 at 10:35


















0














Maybe this way :



ListView.builder(
itemBuilder: (BuildContext context, int index)
return Text(data[index]);
,
)





share|improve this answer























  • nope, This just helps build the list. Which I am already doing.

    – punjabi4life
    Mar 7 at 12:09










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043133%2fhow-to-handle-searching-large-lists-in-flutter%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Contains is expensive



Contains-queries are expensive, because every entry needs to be checked at every position (up to value.length - searchTerm.length) if the search term can be found.



Limiting search support to the beginning of the string would improve performance a lot already. In addition you could create helper data-structures where the whole list of values is split into parts with the same character at the beginning. If the chunks are still too big another level could be added for the 2nd character. The lookup would be fast because there are only a limited number of characters.



Using a database might take off some programming work (maintaining indexes). A database like SQLite could be used with indexes specialized to your kind of queries.



Split into smaller chunks of work to allow the framework to do its work



If you can't limit to "beginning of string"-search, you could still split the data structure into smaller chunks and invoke search for each chunk async. This way the UI gets "some air to breath" to re-render the UI before the next chunk is searched. The search result would be updated incrementally.



Move work off the UI thread



Another way would be to start up another isolate and do the search there. Another isolate can run on another CPU (core) and therefore would not block the UI thread when searching. This way it wouldn't be necessary to split into chunks. It might still be advantageous though to incrementally update the UI instead of keeping the user waiting until the whole search result becomes available.



See also



  • https://api.dartlang.org/stable/2.2.0/dart-isolate/dart-isolate-library.html

  • https://pub.dartlang.org/packages/isolate

  • https://codingwithjoe.com/dart-fundamentals-isolates/

Caching



It might also help improve performance to keep search results in memory. For example if the user enters foo and then presses backspace then you could reuse the search result for fo that you previously calculated already, but that only helps in some cases.



Measuring



Another important point of course is to do benchmarking. Whatever you try to improve performance, create benchmarks to learn what measures have what effect and if it's worth it. You'll learn a lot about your scenario, your data, Dart, ..., and this will allow you to make good decisions.






share|improve this answer

























  • After trying to move the work of the UI thread and not getting the results I I needed, the other methods did not fit my needs. I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List<SomeDataStruct> and then adding .toList behind the return.

    – punjabi4life
    Mar 9 at 5:40











  • Interesting. Can't imagine why this helps.

    – Günter Zöchbauer
    Mar 9 at 8:51











  • Yeah, it works now. App doesn't slow down like it would before. I have made an edit to my post showing the new code.

    – punjabi4life
    Mar 9 at 10:35















1














Contains is expensive



Contains-queries are expensive, because every entry needs to be checked at every position (up to value.length - searchTerm.length) if the search term can be found.



Limiting search support to the beginning of the string would improve performance a lot already. In addition you could create helper data-structures where the whole list of values is split into parts with the same character at the beginning. If the chunks are still too big another level could be added for the 2nd character. The lookup would be fast because there are only a limited number of characters.



Using a database might take off some programming work (maintaining indexes). A database like SQLite could be used with indexes specialized to your kind of queries.



Split into smaller chunks of work to allow the framework to do its work



If you can't limit to "beginning of string"-search, you could still split the data structure into smaller chunks and invoke search for each chunk async. This way the UI gets "some air to breath" to re-render the UI before the next chunk is searched. The search result would be updated incrementally.



Move work off the UI thread



Another way would be to start up another isolate and do the search there. Another isolate can run on another CPU (core) and therefore would not block the UI thread when searching. This way it wouldn't be necessary to split into chunks. It might still be advantageous though to incrementally update the UI instead of keeping the user waiting until the whole search result becomes available.



See also



  • https://api.dartlang.org/stable/2.2.0/dart-isolate/dart-isolate-library.html

  • https://pub.dartlang.org/packages/isolate

  • https://codingwithjoe.com/dart-fundamentals-isolates/

Caching



It might also help improve performance to keep search results in memory. For example if the user enters foo and then presses backspace then you could reuse the search result for fo that you previously calculated already, but that only helps in some cases.



Measuring



Another important point of course is to do benchmarking. Whatever you try to improve performance, create benchmarks to learn what measures have what effect and if it's worth it. You'll learn a lot about your scenario, your data, Dart, ..., and this will allow you to make good decisions.






share|improve this answer

























  • After trying to move the work of the UI thread and not getting the results I I needed, the other methods did not fit my needs. I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List<SomeDataStruct> and then adding .toList behind the return.

    – punjabi4life
    Mar 9 at 5:40











  • Interesting. Can't imagine why this helps.

    – Günter Zöchbauer
    Mar 9 at 8:51











  • Yeah, it works now. App doesn't slow down like it would before. I have made an edit to my post showing the new code.

    – punjabi4life
    Mar 9 at 10:35













1












1








1







Contains is expensive



Contains-queries are expensive, because every entry needs to be checked at every position (up to value.length - searchTerm.length) if the search term can be found.



Limiting search support to the beginning of the string would improve performance a lot already. In addition you could create helper data-structures where the whole list of values is split into parts with the same character at the beginning. If the chunks are still too big another level could be added for the 2nd character. The lookup would be fast because there are only a limited number of characters.



Using a database might take off some programming work (maintaining indexes). A database like SQLite could be used with indexes specialized to your kind of queries.



Split into smaller chunks of work to allow the framework to do its work



If you can't limit to "beginning of string"-search, you could still split the data structure into smaller chunks and invoke search for each chunk async. This way the UI gets "some air to breath" to re-render the UI before the next chunk is searched. The search result would be updated incrementally.



Move work off the UI thread



Another way would be to start up another isolate and do the search there. Another isolate can run on another CPU (core) and therefore would not block the UI thread when searching. This way it wouldn't be necessary to split into chunks. It might still be advantageous though to incrementally update the UI instead of keeping the user waiting until the whole search result becomes available.



See also



  • https://api.dartlang.org/stable/2.2.0/dart-isolate/dart-isolate-library.html

  • https://pub.dartlang.org/packages/isolate

  • https://codingwithjoe.com/dart-fundamentals-isolates/

Caching



It might also help improve performance to keep search results in memory. For example if the user enters foo and then presses backspace then you could reuse the search result for fo that you previously calculated already, but that only helps in some cases.



Measuring



Another important point of course is to do benchmarking. Whatever you try to improve performance, create benchmarks to learn what measures have what effect and if it's worth it. You'll learn a lot about your scenario, your data, Dart, ..., and this will allow you to make good decisions.






share|improve this answer















Contains is expensive



Contains-queries are expensive, because every entry needs to be checked at every position (up to value.length - searchTerm.length) if the search term can be found.



Limiting search support to the beginning of the string would improve performance a lot already. In addition you could create helper data-structures where the whole list of values is split into parts with the same character at the beginning. If the chunks are still too big another level could be added for the 2nd character. The lookup would be fast because there are only a limited number of characters.



Using a database might take off some programming work (maintaining indexes). A database like SQLite could be used with indexes specialized to your kind of queries.



Split into smaller chunks of work to allow the framework to do its work



If you can't limit to "beginning of string"-search, you could still split the data structure into smaller chunks and invoke search for each chunk async. This way the UI gets "some air to breath" to re-render the UI before the next chunk is searched. The search result would be updated incrementally.



Move work off the UI thread



Another way would be to start up another isolate and do the search there. Another isolate can run on another CPU (core) and therefore would not block the UI thread when searching. This way it wouldn't be necessary to split into chunks. It might still be advantageous though to incrementally update the UI instead of keeping the user waiting until the whole search result becomes available.



See also



  • https://api.dartlang.org/stable/2.2.0/dart-isolate/dart-isolate-library.html

  • https://pub.dartlang.org/packages/isolate

  • https://codingwithjoe.com/dart-fundamentals-isolates/

Caching



It might also help improve performance to keep search results in memory. For example if the user enters foo and then presses backspace then you could reuse the search result for fo that you previously calculated already, but that only helps in some cases.



Measuring



Another important point of course is to do benchmarking. Whatever you try to improve performance, create benchmarks to learn what measures have what effect and if it's worth it. You'll learn a lot about your scenario, your data, Dart, ..., and this will allow you to make good decisions.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 7 at 12:35

























answered Mar 7 at 12:27









Günter ZöchbauerGünter Zöchbauer

333k711009942




333k711009942












  • After trying to move the work of the UI thread and not getting the results I I needed, the other methods did not fit my needs. I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List<SomeDataStruct> and then adding .toList behind the return.

    – punjabi4life
    Mar 9 at 5:40











  • Interesting. Can't imagine why this helps.

    – Günter Zöchbauer
    Mar 9 at 8:51











  • Yeah, it works now. App doesn't slow down like it would before. I have made an edit to my post showing the new code.

    – punjabi4life
    Mar 9 at 10:35

















  • After trying to move the work of the UI thread and not getting the results I I needed, the other methods did not fit my needs. I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List<SomeDataStruct> and then adding .toList behind the return.

    – punjabi4life
    Mar 9 at 5:40











  • Interesting. Can't imagine why this helps.

    – Günter Zöchbauer
    Mar 9 at 8:51











  • Yeah, it works now. App doesn't slow down like it would before. I have made an edit to my post showing the new code.

    – punjabi4life
    Mar 9 at 10:35
















After trying to move the work of the UI thread and not getting the results I I needed, the other methods did not fit my needs. I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List<SomeDataStruct> and then adding .toList behind the return.

– punjabi4life
Mar 9 at 5:40





After trying to move the work of the UI thread and not getting the results I I needed, the other methods did not fit my needs. I seem to have fixed it by changing the Iterable<SomeDataStruct> to a List<SomeDataStruct> and then adding .toList behind the return.

– punjabi4life
Mar 9 at 5:40













Interesting. Can't imagine why this helps.

– Günter Zöchbauer
Mar 9 at 8:51





Interesting. Can't imagine why this helps.

– Günter Zöchbauer
Mar 9 at 8:51













Yeah, it works now. App doesn't slow down like it would before. I have made an edit to my post showing the new code.

– punjabi4life
Mar 9 at 10:35





Yeah, it works now. App doesn't slow down like it would before. I have made an edit to my post showing the new code.

– punjabi4life
Mar 9 at 10:35













0














Maybe this way :



ListView.builder(
itemBuilder: (BuildContext context, int index)
return Text(data[index]);
,
)





share|improve this answer























  • nope, This just helps build the list. Which I am already doing.

    – punjabi4life
    Mar 7 at 12:09















0














Maybe this way :



ListView.builder(
itemBuilder: (BuildContext context, int index)
return Text(data[index]);
,
)





share|improve this answer























  • nope, This just helps build the list. Which I am already doing.

    – punjabi4life
    Mar 7 at 12:09













0












0








0







Maybe this way :



ListView.builder(
itemBuilder: (BuildContext context, int index)
return Text(data[index]);
,
)





share|improve this answer













Maybe this way :



ListView.builder(
itemBuilder: (BuildContext context, int index)
return Text(data[index]);
,
)






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 12:04









julient-monisnapjulient-monisnap

147




147












  • nope, This just helps build the list. Which I am already doing.

    – punjabi4life
    Mar 7 at 12:09

















  • nope, This just helps build the list. Which I am already doing.

    – punjabi4life
    Mar 7 at 12:09
















nope, This just helps build the list. Which I am already doing.

– punjabi4life
Mar 7 at 12:09





nope, This just helps build the list. Which I am already doing.

– punjabi4life
Mar 7 at 12:09

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043133%2fhow-to-handle-searching-large-lists-in-flutter%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко