fsprojects / FSharp.Data

F# Data: Library for Data Access
https://fsprojects.github.io/FSharp.Data
Other
806 stars 288 forks source link

Update FSharp.Core from 5 to 6 or 7, to get less memory usage and better performance #1494

Closed Thorium closed 3 months ago

Thorium commented 8 months ago

We should update F# core, to get better features, for example, how much class-wrapping is doing the nicePascalName etc in NamingUtils just because it doesn't use Structs.

This would be way more performant code with less memory-consumption:

let private tryAt (s: string) i =
    if i >= s.Length then ValueNone else ValueSome s.[i]

let private sat f (c: voption<char>) =
    match c with
    | ValueSome c when f c -> ValueSome c
    | _ -> ValueNone

[<return: Struct>]
let private (|EOF|_|) c =
    match c with
    | ValueSome _ -> ValueNone
    | _ -> ValueSome()

[<return: Struct>]
let private (|LetterDigit|_|) = sat Char.IsLetterOrDigit
[<return: Struct>]
let private (|Upper|_|) = sat (fun c -> Char.IsUpper c || Char.IsDigit c)
[<return: Struct>]
let private (|Lower|_|) = sat (fun c -> Char.IsLower c || Char.IsDigit c)

But it doesn't compile, because F# 5. So could it be updated to latest stable 7.0.401? Or even 6.0.x to get the structs. Even worse, these utils are used as paket file references in other F# libraries, causing them to waste resources too.

cartermp commented 7 months ago

I think FSharp.Core 6 is workable, provided these constructs are netstandard2.0 compatible. I think they are.

Another alternative is to just rewrite the routine to be more iterative/procedural and use a stringbuilder, likely avoiding more allocations and work.

dsyme commented 3 months ago

Closing as #1495 is merged

Thorium commented 3 months ago

Thanks, is there any plans to release a new version to NuGet?

cartermp commented 3 months ago

ohhh boy I intended to do that last fall, then it didn'thappen. Let me get on that