Host stream write buffer for message oriented transmits #447
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Firmata never really moved on from its serial MIDI roots to frame oriented host connections like Ethernet. It took me a while to figure it out but the problem is easy to verify with a network sniffer like tcpdump: every data byte is currently transferred separately. With TCP/IP the minimum overhead is factor 40, with WiFi even higher. No wonder the W5100 gets burning hot, switch LEDs blink like wild and the host CPU load is higher than expected e.g. when using Serial Firmata to transfer 64 byte messages every 100 millis. This example is not everyone's use case but still there is something simple that can be done to remedy this problem for all use cases: adding a write buffer to the host stream implementations like EthernetStream and WiFiStream that gets flushed with every call to Stream.maintain() at the end of each Firmata main loop.
Using a write buffer has the following advantages: