Skip to content

Add buffering for all output to improve performance with many small strings - #48

Merged
unwiredben merged 1 commit into
sirleech:masterfrom
ribbons:buffer-output
Jan 29, 2014
Merged

unwiredben merged 1 commit into
sirleech:masterfrom
ribbons:buffer-output

Conversation

@ribbons

@ribbons ribbons commented Jan 16, 2014

Copy link
Copy Markdown
Contributor

The project I'm working on at the moment builds a fairly large table a cell at a time, which takes a noticeable amount of time to load in a browser due to the small packets being sent across the network.

I propose to update WebServer::write(uint8_t) to write to a buffer instead of sending single characters (or short strings) as small packets. This PR also removes the other signatures of write so that the base ones in the Print class (which call write(uint8_t)) are used instead and simplifies the writeP/printP definitions to do this too.

This greatly improves the performance of pages which are built from a large number of small strings or values at the expense of a small additional amount of memory (which defaults to 32k but can be adjusted with the use of a new macro called WEBDUINO_OUTPUT_BUFFER_SIZE) and also saves 86 bytes of flash in my particular project into the bargain.

Update WebServer::write(uint8_t) to write to a buffer instead of sending
single characters (or short strings) as small packets.  Remove the other
signatures of write so that the base ones in the Print class (which call
write(uint8_t)) are used instead and simplify the writeP/printP
definitions to do this too.

This greatly improves the performance of pages which are built from a
large number of small strings or values at the expense of a small
additional amount of memory (which can be adjusted with the use of a new
macro called WEBDUINO_OUTPUT_BUFFER_SIZE) and also saves ~85 bytes of
flash.
@unwiredben

Copy link
Copy Markdown
Collaborator

Seems like a good patch to me... does this require a certain version of the Arduino library code in order to use the byte write call from the print methods?

@ribbons

ribbons commented Jan 16, 2014

Copy link
Copy Markdown
Contributor Author

Ah, good point - I hadn't thought of that. Have had a quick check and by the looks of it the Print::print methods have called write(uint8_t) for each character in strings passed to them since the class was initially added in arduino/Arduino@1a89112, so think we should be okay.

@ribbons

ribbons commented Jan 28, 2014

Copy link
Copy Markdown
Contributor Author

@unwiredben Is there anything else that I can clarify or any adjustments that I should make to this PR before it is okay to merge?

@unwiredben

Copy link
Copy Markdown
Collaborator

oh, sorry --- just been very busy. I'll merge today.

On Tue, Jan 28, 2014 at 11:24 AM, Matt Robinson [email protected]:

@unwiredben https://github.com/unwiredben Is there anything else that I
can clarify or any adjustments that I should make to this PR before it is
okay to merge?

Reply to this email directly or view it on GitHubhttps://github.com//pull/48#issuecomment-33501191
.

unwiredben added a commit that referenced this pull request Jan 29, 2014
Add buffering for all output to improve performance with many small strings
@unwiredben
unwiredben merged commit 338ef29 into sirleech:master Jan 29, 2014
@ribbons
ribbons deleted the buffer-output branch January 29, 2014 17:59
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