Skip to content

perf(dashboard): use lightweight streamed reads for note excerpts#1886

Open
joshtrichards wants to merge 3 commits into
mainfrom
jtr/perf-dashboard-excerpt
Open

perf(dashboard): use lightweight streamed reads for note excerpts#1886
joshtrichards wants to merge 3 commits into
mainfrom
jtr/perf-dashboard-excerpt

Conversation

@joshtrichards
Copy link
Copy Markdown
Member

@joshtrichards joshtrichards commented Jun 4, 2026

Summary

Optimize note excerpt generation by reading only a small prefix of the file instead of loading the full note content.

Changes

  • add a lightweight best-effort excerpt source reader by switching from the File API's getContent to own fopen/fread
  • read only a bounded prefix sized for excerpt generation
  • trim incomplete trailing UTF-8 bytes with mb_strcut()
  • preserve existing excerpt formatting behavior after markdown stripping
  • return an empty excerpt if the lightweight preview read fails, instead of falling back to a full file read
  • additional optimization: use pre-compiled string literal for BOM stripping eliminating need for pack() at runtime
  • also fixes a small bug: $title is typed as string and empty() ends up being true on things like "0".

Why

Excerpt generation only needs roughly the first 100 visible characters, so reading the entire note is unnecessary work. This change reduces I/O and memory usage for note list rendering, especially for larger notes or slower storage backends.

Notes

  • this is intentionally a performance-oriented heuristic, not a full-fidelity content read
  • markdown-heavy prefixes may occasionally produce shorter previews than before
  • full note reads remain unchanged via getContent()

Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards added bug Something isn't working enhancement New feature or request feature: dashboard Related to Nextcloud dashboard 3. to review performance 🚀 labels Jun 4, 2026
Signed-off-by: Josh <josh.t.richards@gmail.com>
(not using ISimpleFile oops)

Signed-off-by: Josh <josh.t.richards@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review bug Something isn't working enhancement New feature or request feature: dashboard Related to Nextcloud dashboard performance 🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant