40% faster JSON serialization with Source Generators in .NET 6

preview_player
Показать описание

Hello everybody I'm Nick and in this video I will show you how you can use the newly added source generator feature for System.Text.Json to get real world improvements of up to 40% in your code bases.

Don't forget to comment, like and subscribe :)

Social Media:

#csharp #dotnet #sourcegenerators
Рекомендации по теме
Комментарии
Автор

I mean... when the IDE suggests Nick Cage, you use Nick Cage.

wesplybon
Автор

Someone: How did you become better at software development?

Me: I've been watching YouTube videos from Nick Cage

kblyr
Автор

Nice! Do you know if this will be integrated into the automatic de/serialisation for web API? I'm sure there are opportunities to improve this so that we can associate the serialisation context with its respective class to eliminate the need to provide the type in every endpoint. I would assume it could be done with a tiny config in the startup/builder coupled with naming conventions.

dominicc
Автор

Last time I looked at the STJ source generator it actually only generated custom serialization for serialization, not for deserialization, so that matches your results.

NotInventedHereShow
Автор

Nice video as always... did u try with a very long json? I wonder if the benchmark improves with less reflection in a class with a lot of properties

uccc
Автор

Nice video! How does this work when serializing/deserializing dictionaries?

mr_sweez
Автор

Excellent presentation in your video. Moved very quickly, and still easy to follow.

dondumitru
Автор

Nice video! Im just curious, but why make another class (PersonJsonContext) instead of just using serialize, wouldn't that be more typing and more files to manage?

flamendless
Автор

Great work and great way to dumb it down for us! Thank you I am now a subscriber.

Gioandgoose
Автор

I noticed on my own project that adding this immediately failed the project. The List<string> that was serialized previously suddenly stopped working. I'll have to investigate later why.

JustinMinnaar
Автор

I recommend putting on captions with the mix of that accent and speed of talking.

WhitbyStuff
Автор

Is this in a repo we can play with? I'd like to see how a `ToJson` method on the class would perform compared to the converters. For simple classes, and when you know the values won't contain JSON characters, it might be the fastest. Risky, but fast.

BernhardHofmann
Автор

By the way for context, I had a method taking 12-14 seconds, huge payload, down to 2 seconds so now to optimize the remaining code. Literally gona make me look so good at work lol

Gioandgoose
Автор

Great video! Well explained and easy to follow.

Joxel
Автор

Can this be made into a more generic method - more classes can be added to the context, but what if we want to pass any object into this method, could it find the type and utilise the correct jsontypeinfo for serialisation, pass this data with it and use this for the deserialisation...?

MatthewHudson
Автор

If there are multiple errors during serialization I want to return all of them to the client what's the best way to do this?

KeondreLucas
Автор

Hi Nick, do you know how to get the source generated serializer to accept and work with double.NaN values?
I have spent some time researching it but, at least for me, setting does not work with the source generated JSON context..

Dokug
Автор

Interesting stuff as usually, love your videos. Btw, can you setup some converters or other things with this method like you normally do with attributes on properties?

lordicemaniac
Автор

Till you make your class partial (We leverage builder patterns created with a source generate. Seems partial isn't supported yet.

jamesmelvin
Автор

Thanks for this video. I have read a little about source generation and found it confusing, but it was really well explained here and helped to see it visually.

sub
join shbcf.ru