Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Serial Monitor Performances #524

Merged
merged 11 commits into from
Oct 5, 2021
Merged

Improve Serial Monitor Performances #524

merged 11 commits into from
Oct 5, 2021

Conversation

fstasi
Copy link
Contributor

@fstasi fstasi commented Oct 5, 2021

Why

Serial monitor is affected by performance issues: basically it's not able to keep up with the grpc messages arriving from the CLI when a decent amount of message (>100/sec) is being sent from the board.

There are a number of reasons causing this undesirable effect:

  • the communication between Frontend and Backend is very chatty: the FE basically pulls a message at a time from the BE and gets notified when a new message arrives (see comment)
  • The frontend re-renders the whole list of messages every time a new one is pulled
  • JRPC is used to marshal/unmarshal the data, causing additional overhead to the messages
  • all messages are aggregated (and then printed), without any limit to the maximum number

How

A new architecture for the communication has been designed:

  • the backend collects the messages from the CLI and aggregates them in array.
  • every 32 milliseconds the BE sends a chunk of message to the FE, containing all messages arrived in the 32msc timeframe. The reason behind the "32" milliseconds is the refresh rate of the electron application (32msec ~= 30fps). 16ms would guarantee a 60fps, but at the cost of more CPU and reduced responsiveness in the IDE2 GUI
  • the communication between FE and BE is now a "raw" WebSocket connection, without the overhead of JRPC.
  • as the frontend receives the chunk of messages, it adds them to its internal state, assigning them a timestamp and removing the old ones when the buffer size is reached
  • the frontend renders only the messages that are actually in the monitor window: this allows to dramatically reduce the CPU usage as only a few messages are printed, rather than millions

How to test

  • upload a sketch with Serial.print or Serial.println and use no delay in order to have a high throughput of data flowing from the board
  • open the serial monitor in the IDE2

Related issues

fixes #391, fixes #79, fixes #519

Copy link
Contributor

@AlbyIanna AlbyIanna left a comment

Choose a reason for hiding this comment

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

🚀

@AlbyIanna AlbyIanna merged commit ca23e0f into main Oct 5, 2021
fstasi added a commit that referenced this pull request Oct 6, 2021
Co-authored-by: Alberto Iannaccone <a.iannaccone@arduino.cc>
@fstasi fstasi deleted the grpc-performance branch October 6, 2021 08:43
@per1234 per1234 added topic: code Related to content of the project itself topic: serial monitor Related to the Serial Monitor type: enhancement Proposed improvement labels Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself topic: serial monitor Related to the Serial Monitor type: enhancement Proposed improvement
Projects
None yet
4 participants