Skip to content

Improve the perf of qtfb: wait for one rendered frame instead of a hardcoded 1 s sleep - #86

Open
jiaaom wants to merge 1 commit into
asivery:masterfrom
jiaaom:qtfb-wait-for-frame-not-sleep
Open

jiaaom wants to merge 1 commit into
asivery:masterfrom
jiaaom:qtfb-wait-for-frame-not-sleep

Conversation

@jiaaom

@jiaaom jiaaom commented Nov 11, 2026 •

Copy link
Copy Markdown

Hi asivery! First of all, thank you for AppLoad. It is what makes third-party apps on the Paper Pro family possible at all, and it has been a joy to build on.

While writing a small app for my Paper Pro Move, I ran into a 1 s pause on every refresh-mode change and dug into why. Here is what I found, and a fix that I hope is useful.

Every time a qtfb app changes its refresh mode or asks for a full refresh, AppLoad currently pauses that app's connection for a fixed 1 second. This PR replaces the fixed pause with "wait until the change has actually been drawn", which on a Paper Pro Move takes about 40 ms (way faster). Apps that switch modes, such as KOReader, become noticeably more responsive.
No client changes are needed.

What this PR changes

The sleep is replaced with a small helper, runOnGuiAndAwaitFrame():

  • It runs the change on the GUI thread. If nothing actually changed (same refresh mode), it returns at once.
  • Otherwise it waits until the window has rendered one more frame.

Perf

Measured on a reMarkable Paper Pro Move:

Situation Before After
Refresh-mode switch, until the next draw update is handled > 1 s ~40 ms
Request for the mode that is already active 1 s instant
Full-refresh request 1 s one frame

Compatibility: the socket protocol and the client libraries are unchanged, so existing apps work as before, only faster.

Testing

Built from v0.6.0 plus this patch with the CI toolchain image.
Tested on a reMarkable Paper Pro Move (OS 3.29.1.0):

  • A small qtfb test app that switches modes and requests full refreshes.
  • KOReader with its native qtfb backend: buttons, menus and full refreshes no longer lag. I compared it side by side with the original one, and did not notice any degradation or visual artifacts.

[Update] Simplified PR.

MESSAGE_SET_REFRESH_MODE and MESSAGE_REQUEST_FULL_REFRESH called
safetyWaitForEventLoopToCatchUp(), a fixed 1 s sleep on the client's
handler thread, on every request -- including a switch to the mode that
is already active. Apps that change modes often (KOReader through the
shim, or anything that uses ANIM for scrolling and zooming) stall for
a second each time.

Ordering is already guaranteed: queued invocations to the same object
run in FIFO order on the GUI thread, so the mode change always lands
before later updates. What the sleep really bought was "the new mode
has reached the screen before the client continues". This change keeps
that guarantee but waits for the actual event: the change runs on the
GUI thread, then the handler waits for the window's next frameSwapped /
afterRendering, with a 300 ms timeout as a fallback. Requests that do
not change the mode return immediately.

Tested on a reMarkable Paper Pro Move (OS 3.29.1.0, AppLoad v0.6.0 +
this patch): a mode switch to ANIM now takes ~40 ms before the next
update is processed (was >= 1 s), same-mode requests take no time, and
no frame-wait timeout fired in 30 minutes of mixed use.
@kashortiexda

kashortiexda commented Nov 12, 2026 •

Copy link
Copy Markdown

Built and tested rM2
It’s very fast but some flashing / flickering especially when using keyboard but not unbearable (keyboard) but the rest is fast!

@ingatellent

ingatellent commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Good luck with your experiments. The delay is deliberately there, since we don't know if xochitl has correctly built in safety measures, when changing update modes rapidly after each other.

You may or may not damage your screen (the actual hardware) with this update (probably most unsafe on the reMarkable Paper Pro or the reMarkable Paper Pro Move). The warranty explicitly mentions, that it does not cover damages caused by running third party software, so you'll need to be willing to take the risk yourself.

I agree, the qtfb implementation in KOReader is horrible, so I don't use the upstream version, but a version where ui and content have the same update mode (so no changes in update mode during use).

An app should never request a screen mode update, if it already uses the mode it wants to change to, but that part of the code is of course save to add.

Also: Please, instead of creating verbose AI generated PR's, you should make a detailed bug report, by creating an issue. See the README:

P.S. Agent PRs will get rejected, and AI-written code in general is not welcome. If you see a problem, please write an issue instead of submitting an AI-written solution as a pull request.

@jiaaom

jiaaom commented Nov 13, 2026 •

Copy link
Copy Markdown
Author

Hi @ingatellent , since this is technically not a bug, I did not create an issue.
Regarding your safety concern, here's what I tested using xochitl with QT_LOGGING_RULES turned on, and here's evidence that the stock notebook UI in xochitl changed modes, twice, in 192ms instead of 1 second in AppLoad:

03:17:00.726      content:1507k, ui:966k
03:17:00.822      ui:14k
03:17:00.918 FULL

@lenoir-byte

Copy link
Copy Markdown

I maintain Inkpage, an EPUB reader that runs through AppLoad on the Paper Pro Move. I have read this patch but have not tested it yet.

The 1 s wait affects us even though we never change the refresh mode. We only send MESSAGE_REQUEST_FULL_REFRESH, about 500
ms after a page is shown. Our next update is then not handled until the sleep ends, so a page turn just after a full refresh
can wait up to 1 s.

On the hardware concern from @ingatellent: I can't say whether rapid mode changes are safe for the panel, so I understand the
caution. Two things I noticed in the code:

  • The sleep is per client connection, so it does not limit how often the panel is refreshed overall.
  • The 5-finger gesture in FBController::touchEvent already emits requestFullRefresh() without this wait.

Would a middle ground work?

  1. Return at once when the requested mode is already active. @ingatellent already called that part safe.
  2. Use this PR's one-frame wait for full-refresh requests.
  3. For real mode changes, enforce a minimum interval, and wait only for the time that remains of it. An isolated change would
    then be fast, and repeated ones would still be throttled.

@asivery, would you accept that, and what minimum interval would you consider safe?

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.

4 participants