Skip to content
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

OutOfMemoryError: Out of Memory #387

Open
fabioselau077 opened this issue Aug 20, 2024 · 10 comments
Open

OutOfMemoryError: Out of Memory #387

fabioselau077 opened this issue Aug 20, 2024 · 10 comments

Comments

@fabioselau077
Copy link

OutOfMemoryError: Out of Memory
File "store_impl.dart", in SembastStore.currentRecords
File "store_impl.dart", in SembastStore.forEachRecords
File "store_impl.dart", in SembastStore.txnFindRecords
File "store_ref_impl.dart", in SembastStoreRefExtensionImpl.findImmutableRecords
File "store_ref_impl.dart", in SembastStoreRefExtension.find

@alextekartik
Copy link
Collaborator

sembast is defintely not memory friendly - see recommendations -, however some things could be done on my side to improve it. Do you have more context information (platform, size of the database, number of records, does it happen right away or after some time, flutter or dart context, even better if you can share your database to help reproducing and investigation)?. Than you!

@haashem
Copy link

haashem commented Sep 4, 2024

I have the same issue and started to show recently. using 3.7.2

Screenshot 2024-09-04 at 18 43 03
Screenshot 2024-09-04 at 18 42 36

I use Sembast to cache network requests:

_store.record(url).put(_sembastDatabase.instance, response);

@alextekartik
Copy link
Collaborator

Indeed compact (that you don't control) is an expensive operation. I would recommend switching to sembast_sqflite, the API is the same, only the factory is different and it will store persistent information in a database instead of a big file and should avoid some memory issues.

@alextekartik
Copy link
Collaborator

Also I don't know how big are your responses (1K, 100K, 10Mb) but if too big, sembast might not be the best solution here.
I would:

  • limit the number of cached request (by adding a timestamp field and clearing old cached response when reaching NNN requests - see recommandations.
  • if response are big (more than 100Kb, you might better store them as file and only store a reference to the file in the sembast database)

@alextekartik
Copy link
Collaborator

(and the compact operation could also be optimized as it doubled the memory usage during the operation, I would look into that)

@haashem
Copy link

haashem commented Sep 4, 2024

Thanks for quick reply. the responses are less than 10 KB, and I have cached around 20 network requests. they will be overwritten by new responses so the size of cache will be less than 50Kb at max.

@alextekartik
Copy link
Collaborator

Indeed that is not a lot. Do you confirm that you don't have more than 20 different url (exactly the same as each url will create a new entry, changing a parameter will change the url) and are you able to share a database I can look at?

@haashem
Copy link

haashem commented Sep 4, 2024

Ohhh, in that case can be many, some urls have query parameters so can cause new record.

I try to share a local db from simulator.

@haashem
Copy link

haashem commented Sep 4, 2024

here you are:

db.sembast.zip

the db size 36 Mb with 150 records!

@alextekartik
Copy link
Collaborator

Indeed this is not in the recommended usage as most of the records are more than 500KB in a json format. I have slightly improve memory usage in compact in sembast in 3.7.3+3 just published but I would recommend:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants