Skip to content

fix(reader): keep ebook search responsive across many short sections - #4371

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/4350-reader-search-yield-across-sections
Nov 23, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/4350-reader-search-yield-across-sections

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #4350
Related issue: N/A
Validation tasks: none (ebooks are a beta feature outside the 1.0 validation board)

Other clients: Apple N/A (no ebook reader); Android N/A (the Android reader has no in-book search); Roku N/A (no ebook reader)

In the web ebook reader (beta), searching a book made of many short sections still freezes the page until the whole book has been read. While it runs, clicks wait, so Back or a new search only takes effect afterwards. #4331 made search pause after 25 ms of work, but the clock restarted at every section. A section that finishes inside 25 ms never paused, and when its document loads without a real wait the next section runs in the same task. FB2 always loads this way, because each section is parsed synchronously.

On a synthetic FB2 with 250 sections of about 4,300 characters, a search for a missing word ran as one 420–460 ms task in headless Chromium, and 1.65–1.8 s with the CPU throttled 4x. With this change, a whole-book search pauses at least every 25 ms of work across the book, and an aborted search stops at the next pause.

Approach

In the vendored foliate-js view.js, a whole-book search now keeps one time budget for all sections. It checks the budget after loading each section's document and after scanning it, pauses for the event loop once 25 ms have passed, and then checks the abort signal. A single-section search keeps its own budget as before. The Silo change is marked in comments.

Validation

  • Reader tests: a new case searches 200 short sections for a missing word and aborts from a timer queued before the search. It fails on main, where all 200 sections are read before the timer runs, and passes here. The existing long-section case now searches one section, so it still checks the pause inside a section's scan. It fails if that pause is removed.
  • Web: lint, format check, typecheck, build, bundle budget check, and the full Vitest suite (891 files, 7,581 tests) pass.
  • verify-local-paths, verify-case-collisions, verify-size-ratchet, and verify-bidi pass. There are no Go, API, or contract changes, so the Go half and the API contract checks were not run.
  • In the browser: a local server built from main and then from this branch, with the same FB2, account and searches. Results are under Evidence.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-4371/

Surface and build: web app ebook reader, main at 39ad6d9 and this branch, same local server data and synthetic FB2. The search panel looks the same and lists the same results. The difference is whether the page responds while a search runs, so the evidence is timing. It was measured in headless Chromium at 1440px on the production bundle, with a long-task observer, a timer due 50 ms after the search click, and real clicks.

Browser measurements (250-section FB2, search for a missing word, three runs each)
main this branch
Longest task 420–461 ms no task over 50 ms
Timer due 50 ms after the click ran late by 385–425 ms 38–41 ms
Back click 100 ms into a search to leaving the reader 356–371 ms 151–189 ms
Search time 480–517 ms 494–567 ms
CPU throttled 4x
Longest task 1,652–1,806 ms no task over 50 ms
Timer due 50 ms after the click ran late by 1,623–1,789 ms 41–50 ms
Search time 1,723–1,740 ms (one run 3,873 ms) 2,034–2,129 ms

On both builds, a search for a common word still stops at 1,000 matches with the "Showing the first 1,000 matches." note, and a search for "Chapter 237" finds one result that opens and highlights that chapter.

Risks

  • Pausing between sections makes a whole-book search slower when the device is slow: about 18% with the CPU throttled 4x on this book. At full speed the difference stayed within run-to-run noise. Each pause is a timer, and browsers enforce a minimum delay on chained timers.
  • Browsers slow timers in a hidden tab, so a search started there finishes later and catches up when the tab is shown again. fix(reader): keep ebook search responsive in long sections with few matches #4331 already did this inside long sections.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code (via T3 Code); Codex CLI for code review
  • Tool(s): Claude Code, Codex CLI, GitHub CLI, Playwright (headless Chromium)
  • Model(s): claude-opus-5-5; gpt-6.1-sol (code review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: dual-code-review of the branch diff at medium effort. claude-opus-5-5 (Claude Code subagent) and gpt-6.1-sol (Codex CLI, read-only) reviewed the same brief independently for correctness, repo standards and the issue's spec, and the results were reconciled.
    • gpt-6.1-sol: no findings.
    • claude-opus-5-5: one medium correctness finding in the test. The new pause after a section loads stopped the long-section case before the scan, so that case no longer checked the pause inside a section. Fixed: the case now searches a single section, and it fails if the in-section pause is removed. Both reviewers re-checked the test change and found nothing further.

A whole-book search restarted its 25 ms budget at every section, so a book
of many short sections (FB2 parses each synchronously) searched in one task
and an abort waited for the end. Track the budget across sections and pause
after loading and after finishing each one.
…arch

The pause after a section loads now stops a whole-book search before the
section scan, so the long-section case searched one section to keep
checking the pause inside it.
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 15, 2026
@silo-kody

silo-kody Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility

@silo-triage silo-triage Bot added bug Something isn't working impact: perf Unusable slowness on normal hardware priority: P2 Limited scope, workaround exists, or polish labels Nov 15, 2026
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Search now shares a 25 ms work budget across book sections and checks for aborts at pause points. Tests cover aborted searches across one long section and many short sections.

Changes: Ebook search responsiveness

Layer / File(s) Summary
Shared pause budget
web/vendor/foliate-js/view.js
A shared pause helper yields when forced or when the 25 ms budget expires. Section matching uses the shared clock and checks for aborts after yielding.
Whole-book search and abort tests
web/vendor/foliate-js/view.js, web/src/reader/FoliateSearch.test.ts
Whole-book search shares one clock across sections and checks for pauses after document creation and matching. Tests check that aborted searches return no results and open no more than the case-specific maximum number of sections.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104

Merge Risk: Minimal · up to 6d90d

Ebook whole-book search now yields on a shared time budget across sections and stops at the next pause after an abort. No actionable merge risk was found, and the change is easy to revert.

Security architecture risk: Minimal · up to 6d90d

The change improves search responsiveness while preserving existing result limits and cancellation controls. Inspection found no introduced or worsened risk materially affecting security, failure containment, rollback, or ownership.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: search in the web ebook reader stays responsive across many short sections. The PR changes the vendored foliate-js view.js so whole-book searches share one 25 ms budget acr…
Linked Issues check Passed Issue #4350 is the only active direct target. Its coding requirements: (1) a whole-book search pauses at least every 25 ms of work across sections, not per section; (2) the budget is checked after loa…
Out of Scope Changes check Passed The PR changes web/vendor/foliate-js/view.js (search budget and yield logic, with comments) and web/src/reader/FoliateSearch.test.ts (new and parameterized search abort tests). Both directly implement…
Description check Passed The description states the problem (ebook whole-book search freezing the page across many short sections), the approach (shared 25 ms time budget in vendored foliate-js view.js with yields and abort c…
Full details: Title check

Explanation

The title names the change: search in the web ebook reader stays responsive across many short sections. The PR changes the vendored foliate-js view.js so whole-book searches share one 25 ms budget across sections, which matches the title's subject and scope. The title is short, single-sentence, and specific.

Full details: Linked Issues check

Explanation

Issue #4350 is the only active direct target. Its coding requirements: (1) a whole-book search pauses at least every 25 ms of work across sections, not per section; (2) the budget is checked after loading a section document and after finishing its scan; (3) an aborted search stops at the next pause. At the reviewed head, web/vendor/foliate-js/view.js defines SEARCH_TIME_BUDGET = 25 and a shared pauseSearch(clock, signal, force) helper. It yields with yieldToEventLoop() when the clock has run 25 ms, resets the clock, and returns whether the signal aborted. The raw summary states that whole-book searches share one clock across sections and check for pauses after document creation and after section matching, and that the abort check follows the pause. The new reader test (200 short sections, abort from a queued timer) covers requirement 1 and 3 in the PR description. The existing long-section test now covers the in-section pause. The #searchBook body was not readable in this inspection (the diff was unavailable), so the conclusion rests on the head helper and the summary's description of the call sites.

Full details: Out of Scope Changes check

Explanation

The PR changes web/vendor/foliate-js/view.js (search budget and yield logic, with comments) and web/src/reader/FoliateSearch.test.ts (new and parameterized search abort tests). Both directly implement or verify issue #4350. The head comment block for the Silo change matches the search-yield intent. No unrelated files are listed in the summary. Go, API, and contract files are not changed, per the PR description. The PR also notes a known cost: throttled whole-book search runs about 18% slower, which is a tradeoff of the requested behavior, not an unrelated change.

Full details: Description check

Explanation

The description states the problem (ebook whole-book search freezing the page across many short sections), the approach (shared 25 ms time budget in vendored foliate-js view.js with yields and abort checks), the tests added or changed, validation runs, browser measurements, and risks. It is directly related to the changeset, so it is not off-topic and not vague.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3b6f4d9e-15c6-4f55-89f6-a56917426382
Commits

Reviewing files that changed from the base of the PR and between 39ad6d9 and 6d90d37.

Files selected for processing: 2

  • web/src/reader/FoliateSearch.test.ts
  • web/vendor/foliate-js/view.js

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@Quick104

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: 6d90d37804. I found no defects and pushed no changes.

What I checked

  • The refactored pause in #matchSection keeps the old behavior. It still pauses every 100 matches, stops when the search is aborted, and restarts the clock after each pause. The only change is that #searchBook now shares one clock across sections, so short sections that load synchronously (FB2) can no longer run back to back in one task.
  • Aborting and superseding a search, the result limit and the truncated marker, progress order, sections without createDocument, and replaying saved results all behave as they did on main.
  • The new "many short sections" test fails on main for the reported reason: the search reads every section before the abort timer runs. It passes on this head, as do the other tests in FoliateSearch.test.ts.
  • A second, read-only review by another model also found nothing. It confirmed in jsdom that main opens all 200 sections before the abort and this head stops after three.

Not verified here: I didn't repeat the browser timing runs; the numbers in the description are the author's. Timer behavior in a hidden tab is also unverified, and the description already names it as a risk.

Possible later improvement (not a blocker): where the browser supports it, scheduler.yield() with a setTimeout fallback would avoid the minimum delay on chained timers, which causes most of the roughly 18% slowdown under CPU throttling.

Validated features: none affected. Ebooks are a beta feature with no cases on the 1.0 validation board.
User manual: no change needed. The ebooks page lists Search only as a reader control.
Other clients: I agree with the N/A entries. The Apple and Android code has no in-book ebook search.

Fit: 9/10 · Readiness: 9/10 — ready

Fit: a small, contained fix for a real freeze in the beta ebook reader, made at the place that causes it, with no new settings or API surface. Readiness: the logic matches the old loop apart from the shared budget, and a test that fails on main proves the fix.

🤖 Claude Code (claude-opus-5-5)

@Quick104
Quick104 merged commit 77965e3 into Silo-Server:main Nov 23, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working impact: perf Unusable slowness on normal hardware priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ebook reader search still blocks the page across many short sections

2 participants