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

The list grows infinitely until the app crashes with OOM #4

Open
Nek-12 opened this issue Aug 19, 2024 · 12 comments
Open

The list grows infinitely until the app crashes with OOM #4

Nek-12 opened this issue Aug 19, 2024 · 12 comments
Assignees
Labels
enhancement New feature or request

Comments

@Nek-12
Copy link

Nek-12 commented Aug 19, 2024

With current implementation, after scrolling through several thousand items, the app crashes with OOM because it fails to allocate a huge list of items. Before that, the app slows down to a halt due to GC pressure.

@Ahmad-Hamwi
Copy link
Owner

Thank you for your observation, may I ask you to test this on a normal list? Not a paginated one. I need first to know whether this is a compose problem or the library's problem.

Also let me know what platform you're on.

@Nek-12
Copy link
Author

Nek-12 commented Aug 19, 2024

The same list if not paginated will also crash the app. Android.

@Ahmad-Hamwi
Copy link
Owner

This means this isn't this library's bug, it is probably a misuse of the lazy list or an actual bug on compose's side.

Are you assigning keys to each item in the list? If not, do it and let me know if it helped. The key should be unique across all items.

@Nek-12
Copy link
Author

Nek-12 commented Aug 19, 2024

This is a library bug on this line

You grow the list infinitely and never let go of the references

@Ahmad-Hamwi
Copy link
Owner

True, otherwise your data will be lost, you won't be able to go back to your previously scrolled data, this isn't the behavior I expect when scrolling in any feed app for example :)

If you suggest any better way of holding the data without a loss, let me know.

@Nek-12
Copy link
Author

Nek-12 commented Aug 19, 2024

Jetpack paging evicts items from the cache on LRU basis and reloads them on scroll back.

@Ahmad-Hamwi
Copy link
Owner

Ahmad-Hamwi commented Aug 19, 2024

You're talking about disk caching, now it makes sense, it is not supported.

I think supporting such optimization will take some time, especially on each platform, I may start with Android.

Will consider such change and I'm open to any contributions.

@Nek-12
Copy link
Author

Nek-12 commented Aug 19, 2024

No I'm not talking about disk caching, I meant an in-memory object pool based on distance to current index.

@Ahmad-Hamwi
Copy link
Owner

Can you provide me with resources on such in-memory object pool? A quick search showed me that it can be the same as an in-memory DB, but I'm not sure how it differs from using heap directly (current implemention) in terms of optimization.

@Ahmad-Hamwi
Copy link
Owner

I would also appreciate a minimal sample project that has produces the crash.

@Nek-12
Copy link
Author

Nek-12 commented Aug 19, 2024

Can you provide me with resources on such in-memory object pool? A quick search showed me that it can be the same as an in-memory DB, but I'm not sure how it differs from using heap directly (current implemention) in terms of optimization.

https://android.googlesource.com/platform/frameworks/support/+/androidx-paging-release/paging/paging-common/src/commonMain/kotlin/androidx/paging/ItemSnapshotList.kt

https://android.googlesource.com/platform/frameworks/support/+/androidx-paging-release/paging/paging-common/src/commonMain/kotlin/androidx/paging/PageStore.kt

@Ahmad-Hamwi Ahmad-Hamwi self-assigned this Aug 20, 2024
@Ahmad-Hamwi Ahmad-Hamwi added the enhancement New feature or request label Aug 20, 2024
@terrakok
Copy link

@Nek-12 instead of the list of objects you can keep paged list of IDs. And every item will load its data by its own. (and will free the memory when the view leave the composition)

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

No branches or pull requests

3 participants