Skip to content

Conversation

benma
Copy link
Collaborator

@benma benma commented Sep 23, 2025

The simulator didn't behave like the real firmware: it only polled/spun the async tasks when there was USB input available, which happens at the client poll interval during a long-running workflow.

Instead, usb_packet_process should be called if there is USB input, but the async tasks should be polled independently at max speed.

We noticed this issue when making bip39-unlock async, and it would only advance by one bip39 stretch iteration every few hundred milliseconds.

The simulator didn't behave like the real firmware: it only
polled/spun the async tasks when there was USB input available, which
happens at the client poll interval during a long-running workflow.

Instead, usb_packet_process should be called if there is USB input,
but the async tasks should be polled independently at max speed.

We noticed this issue when making bip39-unlock async, and it would
only advance by one bip39 stretch iteration every few hundred
milliseconds.
@benma benma requested a review from NickeZ September 23, 2025 08:13
@benma benma marked this pull request as draft September 23, 2025 08:16
@NickeZ
Copy link
Collaborator

NickeZ commented Sep 23, 2025

Does this make the simulator use 100% of one cpu thread?

Maybe a quickfix could be to sleep 10 ms in the main loop?

(the real fix is to change to an event loop that blocks if there is nothing more to do)

Reduce CPU load
@benma
Copy link
Collaborator Author

benma commented Sep 23, 2025

Does this make the simulator use 100% of one cpu thread?

Maybe a quickfix could be to sleep 10 ms in the main loop?

Yeah I have a version where it does a timeout like this (pushed the commit here), but there is no good balance.

  • 10ms still means an unbearably long unlock
  • 0.05ms is still slow with cpu at about 10% (for me)

(the real fix is to change to an event loop that blocks if there is nothing more to do)

That is not an easy thing to do at the moment right?

For now I am abandoning this PR and simply making bip39 unlock not yield in every iteration in the simulator.

@benma benma removed the request for review from NickeZ September 23, 2025 12:56
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.

2 participants