Skip to content

[Screensaver] add a cap to the number of random images processed#14521

Merged
Frenzie merged 3 commits into
koreader:masterfrom
Commodore64user:cap-screensaver
Oct 27, 2025
Merged

[Screensaver] add a cap to the number of random images processed#14521
Frenzie merged 3 commits into
koreader:masterfrom
Commodore64user:cap-screensaver

Conversation

@Commodore64user

@Commodore64user Commodore64user commented Oct 27, 2025

Copy link
Copy Markdown
Member

what's new

  • Added a file_cap parameter to util.findFiles to limit the number of files scanned during directory traversal. The scan stops once the cap is reached.
  • Updated filemanagerutil.getRandomFile to accept and pass the file_cap parameter to util.findFiles, ensuring random file selection respects the cap.
  • Modified _getRandomImage to use the screensaver_file_cap setting (defaulting to 128) for both alphabetical cycling and random image selection, preventing performance issues with large image directories.
  • The cap is configurable via the screensaver_file_cap G_setting.

related issues


This change is Reviewable

Comment thread frontend/ui/screensaver.lua Outdated
local files = {}
local num_files = 0
-- Slippery slope ahead! Ensure the number of files does not become unmanageable, otherwise we'll have performance issues.
-- NOTE: empirically, a kindle 4 found and sorted 128 files in 0.274828 seconds.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this go by the file_cap? I'm not too sure about the name btw: in a programming context it sounds more like capacity than like an arbitrary limit.

Anyway, the actual reason I'm commenting, and I may have said this before, but this sounds like it's a fairly low default even on a Kindle 4?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

256? 300? 500? what do you have in mind? to be fair though, no has complained about the 128. people with 5000+ tend to be the exception not the rule... we know 128 good, 5000 bad. and those same people can now change that value to anything the wish to.

a cap is a limit on something.

@Frenzie Frenzie Oct 27, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The time measurement sounds like 256 or even 512 should still be okay even on the Kindle 4, which is pretty much the worst case scenario. But perhaps you disagree?

Iirc I did some measurements and tests on my old H2O once and decided it was basically okay up to about a thousand, but of course that device is much faster than a Kindle 4, even if it's much slower than my newer Libra 2.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the worst case scenario is really a kindle 2/3, I believe 128 is fine. Most people won't have more than perhaps a few dozen images, besides, is simple enough to increase the cap now. but if you want 256 I am happy to increase it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd make it 256 then, yes.

-- Slippery slope ahead! Ensure the number of files does not become unmanageable, otherwise we'll have performance issues.
-- Power users can increase this cap if needed. Beware though, this grows at O(n * c) where c increases with the number of files.
-- NOTE: empirically, a kindle 4 found and sorted 128 files in 0.274828 seconds.
local file_cap = G_reader_settings:readSetting("screensaver_file_cap") or 256

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@hius07 @poire-z Thoughts on adding this setting?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay.

@Frenzie Frenzie added this to the 2025.10 milestone Oct 27, 2025
@Frenzie Frenzie merged commit 393837b into koreader:master Oct 27, 2025
4 checks passed
@poire-z

poire-z commented Oct 27, 2025

Copy link
Copy Markdown
Contributor
  • file_cap

I would have named it with _nb of max_files, something that reads like it's a number. But too late, so ok.

@Frenzie

Frenzie commented Oct 27, 2025

Copy link
Copy Markdown
Member

Not quite too late; no one's used it yet. Sorry, I thought you were on vacation so I figured I wouldn't wait for you.

@Commodore64user Commodore64user deleted the cap-screensaver branch October 27, 2025 22:30
@Commodore64user

Commodore64user commented Oct 27, 2025

Copy link
Copy Markdown
Member Author

File-cap-nb? A cap is an upper limit imposed to something, it already means maximum and number etc.

Edit: a little example

Sorry, I thought you were on vacation so I figured I wouldn't wait for you.

on the run, something to do with some jewels or something ;)

@poire-z

poire-z commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

File-cap-nb? A cap is an upper limit imposed to something, it already means maximum and number etc.

May be in the wild - but not in our codebase, where explicite is better than english-scholar'ite.

on the run, something to do with some jewels or something ;)

After my font list got ugly radio buttons, I thought I would change trade...
But after one week, I'm missing KOReader :/ I'll give them back if I get back my square checkboxes !

@Commodore64user

Copy link
Copy Markdown
Member Author

May be in the wild - but not in our codebase, where explicite is better than english-scholar'ite.

not sure what is scholar about that... what is it exactly that you want?

@poire-z

poire-z commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

max, nb, files in plural, something that would read like it's a number to someone not familiar with the word "cap" - file_cap would sound to me like a boolean: we cap or we don't cap (to some number defined elsewhere).

@Commodore64user

Commodore64user commented Oct 28, 2025

Copy link
Copy Markdown
Member Author

but you now know what it means... max is already implied as a cap is a max point, nb is also implied as one can only have numerical maxes, and files is grammatically incorrect.

file_count_cap?

Frenzie pushed a commit that referenced this pull request Oct 28, 2025
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
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

Successfully merging this pull request may close these issues.

20 second plus wait time to load sleep screen

4 participants