You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unexpected code size increase when using JSON Source Generator #56995
I tried the JSON Source Generator as asked too. I was surprised to find that my assembly grew from 7 KiB to 125 KiB after adding source generators even though I only generated code for Person and List<Person>.
When looking at the generated code I found a bunch of generated methods that I didn't use and that should be possible to have in a shared library such AssemblySerialize.
It's not really a bug but I felt 120 KiB was a bit too much, especially in a world where we try to squeeze down the size for Blazor WASM Clients.
@layomia Hi. Tried it but after updating the reference my code no longer compiles. It almost seems like the source generator hasn't generated any code as it complains that: error CS0534: 'MyJsonContext' does not implement inherited abstract member 'JsonSerializerContext.GetTypeInfo(Type)'
I tried faking the method but then I got other errors.
It could be because you made some changes to how to use the source generator but I wasn't aware of those.
Thanks for the tips, I managed to build it on Ubuntu in WSL and when inspecting the binaries it looks much better. I no longer see AssemblyWrite and other unrelated metadata. There is metadata generated for Int32 and String which I guess could be in a common assembly but it doesn't take much space.
Activity
layomia commentedon Aug 6, 2021
Thanks for the feedback & analysis of the generator's performance. I believe the size issue is resolved following #56354. The generator was including a bunch of auto-generated members on record types, but those should now be excluded following this PR. You'll be able to try the fix in a couple hours when we have a new build of System.Text.Json - https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet6&view=versions&package=System.Text.Json&version=6.0.0-rc.1.21406.4&protocolType=NuGet. Pls let us know if the issue is resolved.
mrange commentedon Aug 7, 2021
@layomia Hi. Tried it but after updating the reference my code no longer compiles. It almost seems like the source generator hasn't generated any code as it complains that:
error CS0534: 'MyJsonContext' does not implement inherited abstract member 'JsonSerializerContext.GetTypeInfo(Type)'I tried faking the method but then I got other errors.
It could be because you made some changes to how to use the source generator but I wasn't aware of those.
If you are interested see my PR: https://github.com/mrange/T4JsonSerializer/pull/1/files#diff-7f0adf85cf5c2c4802b4e4849b49eb3fd63de1852d53df61da98fadf46604e6fR10
(It also seems the new version has updated transitive dependencies but I downloaded them as well so I hope that's good)
mrange commentedon Aug 7, 2021
I also tried the version you linked but with the same results.
mrange commentedon Aug 9, 2021
Tried
system.text.json.6.0.0-rc.1.21409.2as well and still seems to me that the source generator isn't executed. Perhaps I am doing something wrong?am11 commentedon Aug 9, 2021
@mrange, could you try with the daily build of whole sdk / shared framework (https://github.com/dotnet/installer#installers-and-binaries first column in the table)?
On my Ubuntu box, I did:
it cuts down the size from (128K and 8.0K from last week's build) to:
mrange commentedon Aug 9, 2021
Thanks for the tips, I managed to build it on Ubuntu in WSL and when inspecting the binaries it looks much better. I no longer see
AssemblyWriteand other unrelated metadata. There is metadata generated forInt32andStringwhich I guess could be in a common assembly but it doesn't take much space.danmoseley commentedon Aug 9, 2021
@mrange now you have it working, we'd value any other feedback you may have (if bugs/suggestions then probably as different issues)
Would it make sense to close this one now?
mrange commentedon Aug 9, 2021
Feel free to close this one.