Skip to content

Prefetch medias#18367

Closed
Arthur-Milchior wants to merge 2 commits intoankidroid:mainfrom
Arthur-Milchior:prefetch
Closed

Prefetch medias#18367
Arthur-Milchior wants to merge 2 commits intoankidroid:mainfrom
Arthur-Milchior:prefetch

Conversation

@Arthur-Milchior
Copy link
Member

Prefetch 20 media which are at most 10mb to prepare the answer side

Sometime, the answer side's image are slow to load, and I find it
frustrating as the images were already on the front side. I'm not sure
there is a good way to prepare the answer side webview because of the
javascript part, but we certainly can prepare the media.

This is what I do in a currently very naive heuristic. That is, I
search for src="...", and if the part inside the quote corresponds
to a media that exists, and it weigths at most 10mb, I prefetch it so
that there is no need for file access later. Only the first 20 media
are fetched, in order to limit the memory impact. I expect that:

  • most cards would actually contains less than 20 media and most media
    of less than 10mb, so probably would still improve most cards,
  • the memory usage is probably reasonable as it's already the usage in
    the webview.

If this works well and don't cause any issue, I'd love to do the same
thing for the question side. But I'd need a back-end method that
allows to fetch the potential future question. So I want to experiment
with answer side first.

Also, when the same media appear in both side, it may be interesting
to avoid reading the file twice and instead saving the file during the
first read. This improvement would make sense to do if this experiment
is a success.

If so, doing the same thing for audio can be interesting too.

I believe that using thit `when` makes the various case.
Sometime, the answer side's image are slow to load, and I find it
frustrating as the images were already on the front side. I'm not sure
there is a good way to prepare the answer side webview because of the
javascript part, but we certainly can prepare the media.

This is what I do in a currently very naive heuristic. That is, I
search for `src="..."`, and if the part inside the quote corresponds
to a media that exists, and it weigths at most 10mb, I prefetch it so
that there is no need for file access later. Only the first 20 media
are fetched, in order to limit the memory impact. I expect that:
* most cards would actually contains less than 20 media and most media
of less than 10mb, so probably would still improve most cards,
* the memory usage is probably reasonable as it's already the usage in
the webview.

If this works well and don't cause any issue, I'd love to do the same
thing for the question side. But I'd need a back-end method that
allows to fetch the potential future question. So I want to experiment
with answer side first.

Also, when the same media appear in both side, it may be interesting
to avoid reading the file twice and instead saving the file during the
first read. This improvement would make sense to do if this experiment
is a success.

If so, doing the same thing for audio can be interesting too.
@BrayanDSO
Copy link
Member

Based on the desktop JS code, the new reviewer is supposed to preload the answer side media. Could you test that (without the changes of this PR)?

Comment on lines +59 to +64
try {
WebResourceResponse(guessMimeType(path), null, inputStream)
} catch (_: Exception) {
Timber.d("File $mathjaxAssetPath not found")
null
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a functional change. Exceptions thrown above this aren't catch. And the assertManager.open part is the most likely to throw

@BrayanDSO BrayanDSO added the Needs Author Reply Waiting for a reply from the original author label May 25, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2025

Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Jun 8, 2025
@github-actions github-actions bot closed this Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Author Reply Waiting for a reply from the original author Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants