ClearScript icon indicating copy to clipboard operation
ClearScript copied to clipboard

System.Text.Json and Trimming

Open ColonelBundy opened this issue 2 years ago • 5 comments

Swapping out or providing the ability to swap Newtonsoft for System.Text.Json is highly desirable due to performance reasons.

The upcoming .Net 7 release and it's AOT mode is very attractive and to make this library compatible, we'd need proper annotations and configuration available to make this trimmer friendly.

Is there any plans to support the two use cases?

ColonelBundy avatar Jun 26 '22 20:06 ColonelBundy

Hello @ColonelBundy,

Swapping out or providing the ability to swap Newtonsoft for System.Text.Json is highly desirable due to performance reasons.

Outside of test code, ClearScript currently uses Newtonsoft.Json only for the recently added EnableStringifyEnhancements feature. Is that what you're referring to?

The upcoming .Net 7 release and it's AOT mode is very attractive and to make this library compatible, we'd need proper annotations and configuration available to make this trimmer friendly.

Please elaborate. What new capabilities will ClearScript need in order to support the scenario you're envisioning?

Thanks!

ClearScriptLib avatar Jun 27 '22 15:06 ClearScriptLib

Hello @ColonelBundy,

Swapping out or providing the ability to swap Newtonsoft for System.Text.Json is highly desirable due to performance reasons.

Outside of test code, ClearScript currently uses Newtonsoft.Json only for the recently added EnableStringifyEnhancements feature. Is that what you're referring to?

The upcoming .Net 7 release and it's AOT mode is very attractive and to make this library compatible, we'd need proper annotations and configuration available to make this trimmer friendly.

Please elaborate. What new capabilities will ClearScript need in order to support the scenario you're envisioning?

Thanks!

Yes I'm referrrning to the EnableStringifyEnhancements feature.

For trimming, this is what I'm referring to: https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming Preliminary tests does indicate Clearscript is not properly supported for trimming. I will test more to confirm this, unless I've made a misstake?

ColonelBundy avatar Jun 27 '22 20:06 ColonelBundy

Hi @ColonelBundy,

Yes I'm referrrning to the EnableStringifyEnhancements feature.

We looked into System.Text.Json but went with Json.NET due to the latter's universal compatibility. It's likely that we'll drop support for very old .NET runtime versions at some point, and we'll take another look at System.Text.Json then.

Preliminary tests does indicate Clearscript is not properly supported for trimming.

Certainly. To be honest, AOT is an area we've yet to investigate deeply. At first glance, it's difficult to see how ClearScript could be very functional in such an environment. Not only does it rely heavily on reflection and late binding, but it also enables calls into managed code from scripts – a source that's nowhere to be found at build time. We'll take a closer look.

Thank you!

ClearScriptLib avatar Jun 28 '22 14:06 ClearScriptLib

I too would like if Clearscript supported trimming. :)

cyraid avatar Feb 05 '23 13:02 cyraid

Maybe EnableStringifyEnhancements feature should come with separate plugins (one for Newtonsoft, one for System.Text)

hiyelbaz avatar Feb 05 '23 17:02 hiyelbaz