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

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

Merged
merged 1 commit into from Jan 29, 2014

Conversation

Projects
None yet
2 participants
@ribbons
Copy link
Contributor

commented Jan 16, 2014

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.

Add buffering for all output
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

This comment has been minimized.

Copy link
Collaborator

commented Jan 16, 2014

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

This comment has been minimized.

Copy link
Contributor Author

commented Jan 16, 2014

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

This comment has been minimized.

Copy link
Contributor Author

commented Jan 28, 2014

@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

This comment has been minimized.

Copy link
Collaborator

commented Jan 28, 2014

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

On Tue, Jan 28, 2014 at 11:24 AM, Matt Robinson notifications@github.comwrote:

@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

Merge pull request #48 from ribbons/buffer-output
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 ribbons:buffer-output branch Jan 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.