Skip to content

stdwriter: improve perf by avoiding buffer growth - #8084

Merged
tiborvass merged 4 commits into
moby:masterfrom
unclejack:improve_stdcopy
Sep 17, 2014
Merged

tiborvass merged 4 commits into
moby:masterfrom
unclejack:improve_stdcopy

Conversation

@unclejack

Copy link
Copy Markdown
Contributor

This PR modifies stdwriter to avoid growing the buffer. A lot of memory was being allocated by this line of code:

buf = append(w.prefix[:], buf...)

@LK4D4

LK4D4 commented Sep 17, 2014

Copy link
Copy Markdown
Contributor

I've wrote simple benchmark for Write: https://gist.github.com/LK4D4/acf939a032e1fd1937b1
Here results:

benchmark          old ns/op     new ns/op     delta       
BenchmarkWrite     4009          30.4          -99.24%     

benchmark          old MB/s     new MB/s      speedup     
BenchmarkWrite     1097.53      144689.85     131.83x     

benchmark          old allocs     new allocs     delta        
BenchmarkWrite     1              0              -100.00%     

benchmark          old bytes     new bytes     delta        
BenchmarkWrite     4608          0             -100.00%     

Maybe this is time to move stdcopy to pkg and add this first benchmark.

@unclejack

Copy link
Copy Markdown
Contributor Author

@LK4D4 I'll move it to a package in this PR.

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <[email protected]> (github: unclejack)
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <[email protected]> (github: unclejack)
@unclejack

Copy link
Copy Markdown
Contributor Author

@LK4D4 I've moved stdcopy to pkg/stdcopy. Please feel free to send a PR to this branch on my Docker fork to add the benchmark you've written.

Signed-off-by: Alexandr Morozov <[email protected]>
@LK4D4

LK4D4 commented Sep 17, 2014

Copy link
Copy Markdown
Contributor

@unclejack unclejack#6

Benchmark for StdWriter.Write
@unclejack

Copy link
Copy Markdown
Contributor Author

@LK4D4 Thanks! I've merged the PR.

This PR is ready for review now.

@jessfraz

Copy link
Copy Markdown
Contributor

LGTM I like the cleanup

@tiborvass

Copy link
Copy Markdown
Contributor

LGTM

tiborvass added a commit that referenced this pull request Sep 17, 2014
stdwriter: improve perf by avoiding buffer growth
@tiborvass
tiborvass merged commit 8b97e2c into moby:master Sep 17, 2014
@unclejack
unclejack deleted the improve_stdcopy branch September 17, 2014 16:50
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.

4 participants