fsprojects / FSharp.Data.Adaptive

On-demand adaptive/incremental data for F# https://fsprojects.github.io/FSharp.Data.Adaptive/
MIT License
250 stars 24 forks source link

Is this library trimmable #104

Closed albertwoo closed 2 years ago

albertwoo commented 2 years ago

I am using this library in blazor application, but the size of this library is 1713kb after published. Is it possible to make it trimmable?

krauthaufen commented 2 years ago

Hey, what do you mean by trimmable? I'm not familiar with the term but I assume some sort of dead-code removal?

albertwoo commented 2 years ago

Here is the article from MS: https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming

Simply speaking, if this library is not using reflection then is should be ok to add:

<TrimMode>link</TrimMode>
<IsTrimmable>true</IsTrimmable>

But need to verify that.

krauthaufen commented 2 years ago

It is actually using some reflection bits for building cheap(conservarive) equality comparisons

albertwoo commented 2 years ago

It may need extra work to annotate that.

krauthaufen commented 2 years ago

Basically reflection usage quite limited and iirc only used ror generating these equality-comparers, so it should be fairly easy to get that running, for some datastructures there's a specialized cheap equals method afair which is then used by the reflection code. If you want to look for these things yourself ShallowEquality is the thing to look for. When I have a little time I can investigate this myself but it might take a few days Cheers

krauthaufen commented 2 years ago

I quickly took a look and it basically boils down to one helper function that is only called via reflection, all the other things should be fine as long as the trimming process doesn't remove fields from types, sadly I also can't offer any guarantees that this will work. Maybe publishing the test-project trimmed could be sufficient to show that nothing crucial gets removed...

krauthaufen commented 2 years ago

Just to be clear here we need to build the core library with net6.0 for that to work right?

krauthaufen commented 2 years ago

I have it running in a branch trimmed-publish and a very simple test works

> ls -lh FSharp.Data.Adaptive.dll 
-rw-r--r--  1 schorsch  staff    35K  1 May 19:39 FSharp.Data.Adaptive.dll
> ./PublishTrimmedTest   
20
200

I'll test some more things but it looks good so far

krauthaufen commented 2 years ago

After some local tests I think this works. I'm getting properly trimmed binaries and everything I tested still works as intended.

I'll just get a new version out now so you can test your project with it and I expect nothing to break in absence of trimming. The new version is 1.2.13 and should be on nuget any minute.

Please let me know if your tests are successful. Cheers

albertwoo commented 2 years ago

@krauthaufen it works so great. Currently no errors. And the bundle size is 55KB in compressed in br format for my app.

So great!!! Thanks for your great and quick job!!! 👍🚀

krauthaufen commented 2 years ago

Nice, out of curiosity: what are you using it for?

albertwoo commented 2 years ago

I am building a nuget library for F# developers to write blazor application. Similar to bolero but in my own optionated way. https://github.com/slaveOftime/Fun.Blazor

krauthaufen commented 2 years ago

Cool, nice to see the library in use 👍