Skip to content

Serial Monitor: improved "show timestamp" performance #7911

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

Merged
merged 3 commits into from
Aug 23, 2018

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Aug 22, 2018

I've tested with an Arduino Due printing in a tight-loop on a medium-sized Desktop PC.

Before the patch:

  • cpu usage near 220% (on average)
  • serial monitor laggish

After the patch:

  • cpu usage near 60% (on average), that is very close to disabling "timestamp"
  • serial monitor still responsive

@PaulStoffregen @MichalSy @mfalkvidd @feikname

This patch dramatically reduce pressure on heap memory:

- use a StringTokenizer instead of the very slow String.split(...)
  method to decode newlines. This avoid allocation/deallocation of
  big strings array and use of regexp.
- pre allocate as many object as possible to avoid new allocation
  while streaming data.
- the "timestamp" string is calculated only once per iteration.
- use StringBuilder instead of inline temporary strings (that are,
  again, allocated and deallocated on each iteration)
This saves an access to the Document object (as well as a bunch
temporary object allocations).
This saves another "append" call while streaming.
@cmaglie cmaglie added this to the Release 1.8.6 milestone Aug 22, 2018
@cmaglie cmaglie self-assigned this Aug 22, 2018
@cmaglie cmaglie requested a review from PaulStoffregen August 22, 2018 13:09
@cmaglie cmaglie merged commit d971478 into arduino:master Aug 23, 2018
@cmaglie cmaglie deleted the serial-timestamp-performance branch August 23, 2018 08:46
@per1234 per1234 added the Component: IDE Serial monitor Tools > Serial Monitor label Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: IDE Serial monitor Tools > Serial Monitor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants