-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Combine peekstream and bufferedReader together. #16114
Conversation
63eefb0
to
dff951e
Compare
Looks great! I would like to request 2 things before merging:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a little bit of benchmarking I cannot find any meaningful difference in the speed difference of std.http parsing before and after this change (which makes sense, the overall structure of the buffering remains nearly identical).
All the old test preserved and new add function had added basic tests. I mainly rely on the exist
I need some guides how to acheive this.
Thank @truemedian for benchmarking this change, and thank you for ground up work of std.http and review this pull request. The entire idea of this pull request came from the attempt to deduplicate the code of buffer management in connection, and reuse those for socket, file and the like. |
I'm sorry, I have one more review comment for you, @hawkbee. I would like to challenge the idea of adding |
Many thanks for your review, very glad to see zig becoming better. As we see, the Some other thoughts related: The buffer of Now the reader buffer is 16K for TLS, somewhat small, but user may choose a big buffer size, that may overflow stack for small stack size machine. That voilate allocate small size memory on stack, big size memory on heap. So my attention here is:
|
when test this branch to get https://github.com/MasterQ32/parser-toolkit/archive/master.tar.gz
or frequently this
@andrewrk Sorry to distrurb, could you please have a look the stacktrace to see if this is bug in TLS trigger on this branch or had introduced a bug corruption memory somewhere. Edit: After the following change, both HTTP/HTTPS request download file and diff --git a/lib/std/crypto/tls/Client.zig b/lib/std/crypto/tls/Client.zig
index 37306dd37..edbe50830 100644
--- a/lib/std/crypto/tls/Client.zig
+++ b/lib/std/crypto/tls/Client.zig
@@ -43,7 +43,7 @@ application_cipher: tls.ApplicationCipher,
/// 3. unused
/// The fields `partial_cleartext_idx`, `partial_ciphertext_idx`, and
/// `partial_ciphertext_end` describe the span of the segments.
-partially_read_buffer: [tls.max_ciphertext_record_len]u8,
+partially_read_buffer: [tls.max_ciphertext_record_len * 4]u8,
/// This is an example of the type that is needed by the read and write
/// functions. It can have any fields but it must at least have these
@@ -952,7 +952,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
// too small to fit the cleartext, which may be as large as `max_ciphertext_len`.
var cleartext_stack_buffer: [max_ciphertext_len]u8 = undefined;
// Temporarily stores ciphertext before decrypting it and giving it to `iovecs`.
- var in_stack_buffer: [max_ciphertext_len * 4]u8 = undefined;
+ var in_stack_buffer: [max_ciphertext_len]u8 = undefined;
// How many bytes left in the user's buffer.
const free_size = vp.freeSize();
// The amount of the user's buffer that we need to repurpose for storing |
it does not gain extra benifits for adding this.
underlying buffer is smaller than tokenized token. Add small buffer test BufferedReader tokenize to work as expected. And BufferedReader peek method will work when least param greater than zero.
FWIW, Line 11 in 8fb4a4e
You may want to look into implementing |
See #16114. This functionality should be added to bufferedReader instead.
See #16114. This functionality should be added to bufferedReader instead.
See ziglang#16114. This functionality should be added to bufferedReader instead.
Resolve #4501