Move to a callback-style approach to deserializing objects#72943
Merged
CyrusNajmabadi merged 3 commits intodotnet:mainfrom Apr 8, 2024
Merged
Move to a callback-style approach to deserializing objects#72943CyrusNajmabadi merged 3 commits intodotnet:mainfrom
CyrusNajmabadi merged 3 commits intodotnet:mainfrom
Conversation
Contributor
Author
|
@ToddGrun ptal. note: there is a followup PR to thsi that takes this idea and spreads it much further, avoiding a lot of intermediary list allocs. THat PR also moves to a |
Contributor
Author
|
#72944 is part 2 of this. But shoudl not be reviewed until this goes in. |
CyrusNajmabadi
commented
Apr 8, 2024
|
|
||
| var missingChecksum = missingChecksums[index]; | ||
|
|
||
| AddResult(missingChecksum, missingAsset); |
Contributor
Author
There was a problem hiding this comment.
there are several captures in this lambda. but they will go away in followup pr.
CyrusNajmabadi
commented
Apr 8, 2024
| public static void ReadData<T>( | ||
| Stream stream, Checksum solutionChecksum, int objectCount, ISerializerService serializerService, Action<int, T> callback, CancellationToken cancellationToken) | ||
| { | ||
| var results = new T[objectCount]; |
Contributor
Author
There was a problem hiding this comment.
this is the major alloc removed.
Contributor
|
Nice! |
This was referenced Apr 13, 2024
Contributor
Author
|
@jasonmalinowski For review when you get back. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Followup to #72929
Instead of allocating a large, temporary, array just to pass values around, only to then add those values to a cache, now we just pass a callback to the deserializer to allow it to directly add to the cache.
Note: this also has the benefit of allowing the cache to be filled as we deserialize an item, versus having to deserialize them all. This can help concurrent requests that then may find those items in teh cache, and not have to requery them.
--
Note: it's been a long standing goal of mine to make it so that we can read/write from those pipes without needing the intermediary stream. that would then allow us to populate the cache on the OOP side immediately as objects come across, without having to wait for them all to be written. I intend to make that possible this week.