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

compress/flate: read data with partial flush #68130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vajexal
Copy link

@vajexal vajexal commented Jun 22, 2024

problem: data written with zlib's Z_PARTIAL_FLUSH can't be read because decompressor returns only after Z_SYNC_FLUSH block or data end (not taking into account internal buffer flush). For some protocols it could be crucial, as an example imap client can send command and start waiting for a reply, but server wouldn't be able to read the command, because it will read futher and there will be deadlock

This change makes decompressor return after each block (like zlib's infalte Z_BLOCK flush mode), thus Read calls would be more often. Benchmarks show no difference, but new implementation should be slower. As an option we could add decompressor parameter (flush mode)

before

goos: darwin
goarch: arm64
pkg: compress/flate
cpu: Apple M1
BenchmarkDecode/Digits/Huffman/1e4-8         	   17632	     67686 ns/op	 147.74 MB/s	   40546 B/op	       5 allocs/op
BenchmarkDecode/Digits/Huffman/1e5-8         	    1838	    650723 ns/op	 153.68 MB/s	   40546 B/op	       5 allocs/op
BenchmarkDecode/Digits/Huffman/1e6-8         	     184	   6491793 ns/op	 154.04 MB/s	   40591 B/op	       5 allocs/op
BenchmarkDecode/Digits/Speed/1e4-8           	   17518	     67316 ns/op	 148.55 MB/s	   40627 B/op	       8 allocs/op
BenchmarkDecode/Digits/Speed/1e5-8           	    1708	    699864 ns/op	 142.88 MB/s	   40849 B/op	      11 allocs/op
BenchmarkDecode/Digits/Speed/1e6-8           	     170	   7072273 ns/op	 141.40 MB/s	   44292 B/op	      73 allocs/op
BenchmarkDecode/Digits/Default/1e4-8         	   17760	     67575 ns/op	 147.98 MB/s	   40586 B/op	       7 allocs/op
BenchmarkDecode/Digits/Default/1e5-8         	    1783	    774557 ns/op	 129.11 MB/s	   40831 B/op	      13 allocs/op
BenchmarkDecode/Digits/Default/1e6-8         	     164	   7218230 ns/op	 138.54 MB/s	   44671 B/op	      79 allocs/op
BenchmarkDecode/Digits/Compression/1e4-8     	   17670	     69180 ns/op	 144.55 MB/s	   40592 B/op	       7 allocs/op
BenchmarkDecode/Digits/Compression/1e5-8     	    1646	    726951 ns/op	 137.56 MB/s	   40837 B/op	      13 allocs/op
BenchmarkDecode/Digits/Compression/1e6-8     	     175	   6833131 ns/op	 146.35 MB/s	   44666 B/op	      79 allocs/op
BenchmarkDecode/Newton/Huffman/1e4-8         	   15650	     76928 ns/op	 129.99 MB/s	   41262 B/op	      14 allocs/op
BenchmarkDecode/Newton/Huffman/1e5-8         	    1610	    738391 ns/op	 135.43 MB/s	   45031 B/op	      23 allocs/op
BenchmarkDecode/Newton/Huffman/1e6-8         	     162	   7401724 ns/op	 135.10 MB/s	   79877 B/op	     161 allocs/op
BenchmarkDecode/Newton/Speed/1e4-8           	   20528	     61070 ns/op	 163.75 MB/s	   41167 B/op	      18 allocs/op
BenchmarkDecode/Newton/Speed/1e5-8           	    2224	    530639 ns/op	 188.45 MB/s	   43758 B/op	      31 allocs/op
BenchmarkDecode/Newton/Speed/1e6-8           	     229	   5212735 ns/op	 191.84 MB/s	   81013 B/op	     228 allocs/op
BenchmarkDecode/Newton/Default/1e4-8         	   22993	     52178 ns/op	 191.65 MB/s	   41061 B/op	      15 allocs/op
BenchmarkDecode/Newton/Default/1e5-8         	    2722	    441369 ns/op	 226.57 MB/s	   42891 B/op	      32 allocs/op
BenchmarkDecode/Newton/Default/1e6-8         	     271	   4400777 ns/op	 227.23 MB/s	   61589 B/op	     158 allocs/op
BenchmarkDecode/Newton/Compression/1e4-8     	   22922	     52069 ns/op	 192.05 MB/s	   41062 B/op	      15 allocs/op
BenchmarkDecode/Newton/Compression/1e5-8     	    2715	    439213 ns/op	 227.68 MB/s	   42892 B/op	      32 allocs/op
BenchmarkDecode/Newton/Compression/1e6-8     	     273	   4377611 ns/op	 228.44 MB/s	   63488 B/op	     150 allocs/op
PASS
ok  	compress/flate	45.644s

after

goos: darwin
goarch: arm64
pkg: compress/flate
cpu: Apple M1
BenchmarkDecode/Digits/Huffman/1e4-8         	   17718	     67663 ns/op	 147.79 MB/s	   40544 B/op	       5 allocs/op
BenchmarkDecode/Digits/Huffman/1e5-8         	    1837	    650761 ns/op	 153.67 MB/s	   40546 B/op	       5 allocs/op
BenchmarkDecode/Digits/Huffman/1e6-8         	     183	   6510728 ns/op	 153.59 MB/s	   40591 B/op	       5 allocs/op
BenchmarkDecode/Digits/Speed/1e4-8           	   17732	     67540 ns/op	 148.06 MB/s	   40627 B/op	       8 allocs/op
BenchmarkDecode/Digits/Speed/1e5-8           	    1710	    698022 ns/op	 143.26 MB/s	   40835 B/op	      11 allocs/op
BenchmarkDecode/Digits/Speed/1e6-8           	     168	   7084487 ns/op	 141.15 MB/s	   44294 B/op	      73 allocs/op
BenchmarkDecode/Digits/Default/1e4-8         	   17671	     67873 ns/op	 147.33 MB/s	   40586 B/op	       7 allocs/op
BenchmarkDecode/Digits/Default/1e5-8         	    1776	    676434 ns/op	 147.83 MB/s	   40844 B/op	      13 allocs/op
BenchmarkDecode/Digits/Default/1e6-8         	     175	   6804551 ns/op	 146.96 MB/s	   44666 B/op	      79 allocs/op
BenchmarkDecode/Digits/Compression/1e4-8     	   17640	     67799 ns/op	 147.49 MB/s	   40590 B/op	       7 allocs/op
BenchmarkDecode/Digits/Compression/1e5-8     	    1774	    676699 ns/op	 147.78 MB/s	   40826 B/op	      13 allocs/op
BenchmarkDecode/Digits/Compression/1e6-8     	     175	   6815274 ns/op	 146.73 MB/s	   44666 B/op	      79 allocs/op
BenchmarkDecode/Newton/Huffman/1e4-8         	   15775	     76203 ns/op	 131.23 MB/s	   41254 B/op	      14 allocs/op
BenchmarkDecode/Newton/Huffman/1e5-8         	    1623	    739858 ns/op	 135.16 MB/s	   45031 B/op	      23 allocs/op
BenchmarkDecode/Newton/Huffman/1e6-8         	     162	   7360222 ns/op	 135.87 MB/s	   79876 B/op	     161 allocs/op
BenchmarkDecode/Newton/Speed/1e4-8           	   20624	     58246 ns/op	 171.69 MB/s	   41164 B/op	      18 allocs/op
BenchmarkDecode/Newton/Speed/1e5-8           	    2251	    532092 ns/op	 187.94 MB/s	   43732 B/op	      31 allocs/op
BenchmarkDecode/Newton/Speed/1e6-8           	     229	   5210751 ns/op	 191.91 MB/s	   81012 B/op	     228 allocs/op
BenchmarkDecode/Newton/Default/1e4-8         	   22843	     52362 ns/op	 190.98 MB/s	   41064 B/op	      15 allocs/op
BenchmarkDecode/Newton/Default/1e5-8         	    2716	    440547 ns/op	 226.99 MB/s	   42891 B/op	      32 allocs/op
BenchmarkDecode/Newton/Default/1e6-8         	     271	   4418826 ns/op	 226.30 MB/s	   61588 B/op	     158 allocs/op
BenchmarkDecode/Newton/Compression/1e4-8     	   23104	     52090 ns/op	 191.98 MB/s	   41066 B/op	      15 allocs/op
BenchmarkDecode/Newton/Compression/1e5-8     	    2719	    441339 ns/op	 226.58 MB/s	   42891 B/op	      32 allocs/op
BenchmarkDecode/Newton/Compression/1e6-8     	     271	   4386803 ns/op	 227.96 MB/s	   63458 B/op	     150 allocs/op
PASS
ok  	compress/flate	44.152s

and with 100 blocks (25 vs 100 reads)

before

goos: darwin
goarch: arm64
pkg: compress/flate
cpu: Apple M1
BenchmarkDecodePartialBlocks-8   	     189	   6314697 ns/op	  88.94 MB/s	   40808 B/op	      20 allocs/op
PASS
ok  	compress/flate	6.110s

after

goos: darwin
goarch: arm64
pkg: compress/flate
cpu: Apple M1
BenchmarkDecodePartialBlocks-8   	     188	   6314923 ns/op	  88.94 MB/s	   40846 B/op	      20 allocs/op
PASS
ok  	compress/flate	6.112s

gist partial block generation scripts and benchmark code

@gopherbot
Copy link
Contributor

This PR (HEAD: 69ff43b) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/594215.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/594215.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/594215.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Ian Lance Taylor:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/594215.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Joseph Tsai:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/594215.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from ya l:

Patch Set 1:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/594215.
After addressing review feedback, remember to publish your drafts!

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