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

Setting a thousand of artworks takes a lot of time #623

Closed
arturdryomov opened this issue Sep 2, 2019 · 2 comments
Closed

Setting a thousand of artworks takes a lot of time #623

arturdryomov opened this issue Sep 2, 2019 · 2 comments

Comments

@arturdryomov
Copy link
Contributor

The title sounds ridiculous but it is true.

Since the source I’m working on contains a limited set of images I ship a defined set of declarations in JSON. It contains something like 1500 elements. I read this JSON, transform it to Artwork objects and call MuzeiArtProvider#setArtwork. It works fine but there is a noticeable delay before images actually appear on the UI. It might take almost a minute to do so (on a real device). Timings from an emulator:

Step Time
Reading JSON 69 ms
Transforming to Artwork 23 ms
MuzeiArtProvider#setArtwork 3.514 s
Timeout before images appear 16 s

One thing I’ve noticed right away is a ton of such log entries:

D/MuzeiArtProvider: Notified for batch change on content://ru.ming13.muzei.earthview/1342
D/MuzeiArtProvider: Notified for batch change on content://ru.ming13.muzei.earthview/1341
D/MuzeiArtProvider: Notified for batch change on content://ru.ming13.muzei.earthview/1340

Not sure it is necessary to occupy the thread with logging 1.5 K entries, especially taking into account Uri#toString calls. But the real issue is somewhere else and it occupies the majority of time.

@ianhanniballake
Copy link
Collaborator

We've removed the unconditional logging (it is now tied behind Log.isLoggable() with the MuzeiArtProvider tag) and Muzei 3.4.0 (currently in alpha) drastically improved the loading logic when it comes to that initial huge set of artworks.

ianhanniballake added a commit that referenced this issue Jul 11, 2020
Avoid overloading ContentObservers with individual insert/update/delete Uris and instead only notify on the root content URI.

Found that this improves the cases found in #623 even more.
ianhanniballake added a commit that referenced this issue Jul 11, 2020
Rather than doing the delete operations on a row by row level as a separate batch operation, apply it as part of the same set of operations using selection criteria.

Found that this improves the cases found in #623 even more.
@arturdryomov
Copy link
Contributor Author

Just tried 3.4.0 — the improvement is here, thanks!

However, I’ve increased the artworks count to 2600+ and there is still a visual pause. It’s not as bad as it was though:

Step Time, ms
Reading JSON 126
Transforming to Artwork 25
MuzeiArtProvider#setArtwork 10061

These numbers are from Google Pixel 3a with Android 10 onboard. Timings were taken from the onLoadRequested method. The call was done when I’ve chosen the source in Muzei. Seems like artworks appear when the setArtwork is done.

Not sure if it’s possible to optimize this further.

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

2 participants