fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

Some maintenance question #399

Closed Thorium closed 10 months ago

Thorium commented 10 months ago

This is not so much of an issue, but just a maintenance question...

The Utils module has lot of stuff that I think is pre-ValueOption and UOption could be replaced with VOption. https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/src/ProvidedTypes.fs#L36

I think the utils themselves could also benefit of Spans, for example: https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/src/ProvidedTypes.fs#L55 ...could work something like:

    let splitNameAt (nm:ReadOnlySpan<char>) idx =
        if idx < 0 then failwith "splitNameAt: idx < 0";
        let last = nm.Length - 1
        if idx > last then failwith "splitNameAt: idx > last";
        (nm.Slice(0, idx)), 
        (if idx < last then nm.Slice (idx+1, last - idx) else ReadOnlySpan.Empty)

    let splitILTypeName (nm:ReadOnlySpan<char>) =
        match nm.LastIndexOf '.' with
        | -1 -> UNone, nm
        | idx -> let a, b = splitNameAt nm idx in USome a, b

I would also like to make the DUs without any fields (or only fields of plain non-recursive other DUs) as structs, e.g. here: https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/src/ProvidedTypes.fs#L2737 https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/src/ProvidedTypes.fs#L2952 https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/src/ProvidedTypes.fs#L2973

Why do I even care, is because with a bigger F# solution with multiple type-providers they end-up taking quite a bit of resources, making VS a bit slow, for example this is a part of memory snapshot of VS2022: image

Thorium commented 10 months ago

I tried to change those DUs to structs (https://github.com/fsprojects/FSharp.TypeProviders.SDK/compare/master...Thorium:FSharp.TypeProviders.StarterPack:more-structs), and run some memory & performance analysis with some type-providers and VS, but the difference was within mean square error margin. So no justification for the change.