-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Several improvements to PostData #4312
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
Conversation
New types * `ReadOnlyMemory`, only available in `netstandard2.1` allows you to post `ReadOnlyMemory<byte>` * `StreamHandler` allows you to inject a stream handler and write to the request streams the best way you see fit yourself Performance * `PostData.String` now reuses bytes * `PostData.MultiJson(string[]) uses way less allocations
Expose reusable stream handling on `PostData` Add tests for new types so that they behave and write as expected
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.
LGTM 👍 I left some small comments.
Reading through the post data docs, I think we should consider revising the format of them in a future PR, to focus more on how PostData
can be used with regard to the rest of the client. Happy to open a PR for this.
ms = !string.IsNullOrEmpty(_literalString) ? settings.MemoryStreamFactory.Create(_literalString.Utf8Bytes()) : null; | ||
if (string.IsNullOrEmpty(_literalString)) return; | ||
|
||
var stringBytes = WrittenBytes ?? _literalString.Utf8Bytes(); |
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.
Is WrittenBytes
checked first in the event this is a retry with the same PostData
instance?
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.
Yes, since the string is immutable we allow for PostData.String
to be cached. We could potentially clear _literalString
afterwards.
* Several improvements to PostData New types * `ReadOnlyMemory`, only available in `netstandard2.1` allows you to post `ReadOnlyMemory<byte>` * `StreamHandler` allows you to inject a stream handler and write to the request streams the best way you see fit yourself Performance * `PostData.String` now reuses bytes * `PostData.MultiJson(string[]) uses way less allocations * Move StreamHandler in to its own type. Expose reusable stream handling on `PostData` Add tests for new types so that they behave and write as expected * update post-data docs * Refactor SerializableData and reuse methods from PostData (cherry picked from commit af93854)
* Several improvements to PostData (#4312) * Several improvements to PostData New types * `ReadOnlyMemory`, only available in `netstandard2.1` allows you to post `ReadOnlyMemory<byte>` * `StreamHandler` allows you to inject a stream handler and write to the request streams the best way you see fit yourself Performance * `PostData.String` now reuses bytes * `PostData.MultiJson(string[]) uses way less allocations * Move StreamHandler in to its own type. Expose reusable stream handling on `PostData` Add tests for new types so that they behave and write as expected * update post-data docs * Refactor SerializableData and reuse methods from PostData (cherry picked from commit af93854) * Additional UTF8Json overloads, consolidate how we tell it to write/serialize. (#4313) * Several improvements to PostData New types * `ReadOnlyMemory`, only available in `netstandard2.1` allows you to post `ReadOnlyMemory<byte>` * `StreamHandler` allows you to inject a stream handler and write to the request streams the best way you see fit yourself Performance * `PostData.String` now reuses bytes * `PostData.MultiJson(string[]) uses way less allocations * Adds more write overloads to Utf8Json Either memory stream or to serialize on the writer. This consolidates and funnels places that need to write bytes/streams/objects directly (cherry picked from commit de62914) * add missing hunk after git add -p session (cherry picked from commit fc289b1) * add comment explaining the check for possible fast path in sourceformatter (cherry picked from commit ffc4e46) * Move fastpath check into method and use it for Deserialize too (cherry picked from commit f365b30) * update formatters to use a better check for fast path (cherry picked from commit b07e0a8) * Move StreamHandler in to its own type. Expose reusable stream handling on `PostData` Add tests for new types so that they behave and write as expected * Zap IInternalSerializerWithFormatter * Make sure WriteRaw for memory streams assumes a memorycopy * Make sure final newline is written again for bulk requests * Address PR feedback * reoorder variable assignments (cherry picked from commit fadef66)
New types
ReadOnlyMemory
, only available innetstandard2.1
allows you topost
ReadOnlyMemory<byte>
StreamHandler
allows you to inject a stream handler and write to therequest streams the best way you see fit yourself
Performance
PostData.String
now reuses bytesPostData.MultiJson(string[])
uses way less allocationsBenchmarks current PR posting
10.000
objects (many megabytes overal in size) in various ways.Compare with current master: