Skip to content

Move to a callback-style approach to deserializing objects#72943

Merged
CyrusNajmabadi merged 3 commits intodotnet:mainfrom
CyrusNajmabadi:avoidArray
Apr 8, 2024
Merged

Move to a callback-style approach to deserializing objects#72943
CyrusNajmabadi merged 3 commits intodotnet:mainfrom
CyrusNajmabadi:avoidArray

Conversation

@CyrusNajmabadi
Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Apr 8, 2024

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.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 8, 2024 21:19
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 8, 2024
@CyrusNajmabadi
Copy link
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 TArg-style model so we can do this work without allocating lambdas either. But i wanted to start here to get the ball rolling on the main idea.

@CyrusNajmabadi
Copy link
Contributor Author

#72944 is part 2 of this. But shoudl not be reviewed until this goes in.


var missingChecksum = missingChecksums[index];

AddResult(missingChecksum, missingAsset);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are several captures in this lambda. but they will go away in followup pr.

public static void ReadData<T>(
Stream stream, Checksum solutionChecksum, int objectCount, ISerializerService serializerService, Action<int, T> callback, CancellationToken cancellationToken)
{
var results = new T[objectCount];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the major alloc removed.

@ToddGrun
Copy link
Contributor

ToddGrun commented Apr 8, 2024

Nice!

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@CyrusNajmabadi
Copy link
Contributor Author

@jasonmalinowski For review when you get back.

@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants