Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster CodeGenerator if FSHARP6 defined #407

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Thorium
Copy link
Member

@Thorium Thorium commented Jun 27, 2024

One option for #405

I was testing SwaggerProvider performance issue of fsprojects/SwaggerProvider#150 (comment)
and even though still way too slow, this did gain a few seconds faster execution.

@Thorium
Copy link
Member Author

Thorium commented Jul 7, 2024

This is helping generative TPs (like FSharp.Data and SwaggerProvider) but not erasing providers (like SQLProvider).

src/ProvidedTypes.fs Outdated Show resolved Hide resolved
@vzarytovskii
Copy link

What are some benchmarks with the change?

It adds a lot of clutter and conditional "codegen", where runtime is generally quite fast with reference objects, which don't generally escape gen0.

Also, I don't really remember us (FSharp.Build or elsewhere) to define language constants. Are you sure it works as you expect it to? Or is it TP SDK which takes care of them?

image

@Thorium
Copy link
Member Author

Thorium commented Jul 8, 2024

Because most of the TPs still refer ProvidedTypes.fs as a paket-dependencies file, not as NuGet package, the DefineConstants can be defined in the project referring the file.

It adds a lot of clutter and conditional

We still need a maintenance path for TPs. The current code is old and could be improved. But here, recent 6 weeks you can see that people still use mostly F# 5 and not the latest one. So maybe we need 2 versions? What is a way to separate them, same file, different file, is a political choice not interesting to me.

"codegen", where runtime is generally quite fast

Yeah, right, try the script, it'll complete in a minute (or multiple if you don't have i9 laptop):

#r "nuget: SwaggerProvider"
let [<Literal>] Schema = "https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.sdk.json";;
let t = System.DateTime.Now;; //#time didn't give correct results so let's use the old way...
type Stripe = SwaggerProvider.OpenApiClientProvider<Schema, PreferAsync = true>;;
printfn "%f" (System.DateTime.Now-t).TotalSeconds;;

@cartermp
Copy link
Contributor

cartermp commented Jul 8, 2024

I think there's a separate discussion to be had about if the base dependency should be FSharp.Core 6 or not. I lean towards that as a reasonable choice. But it seems preprocessors are out.

@vzarytovskii
Copy link

Yeah, right, try the script, it'll complete in a minute (or multiple if you don't have i9 laptop):

How does it compare to the changed one? Also, it does involve a bunch of IO, probably better to compare to the already downloaded json.

With local json it runs for 59-ish seconds on my machine.

@Thorium
Copy link
Member Author

Thorium commented Jul 8, 2024

But it seems preprocessors are out.

Would you accept preprocessors at fsproj-level? So that there would be ProvidedTypesOld.fs and ProvidedTypesNew.fs ?

I think lot of F# 4 usage comes from the misunderstanding that the recent F# wouldn't support .NET Framework, and I think .NET Framework is still widely used.

With local json it runs for 59-ish seconds on my machine.

It's all ProvidedTypes.fs that seems to take the time, and there is a lot of work to do here.
It's like 7 megabyte file, handling that with modern computers shouldn't take a minute.

I'm not hoping to get this instant, but if that could be dropped to let's say to 10 seconds, it would also speed-up all the other TPs correspondingly.

This PR was not meant to be the full solution, it's just me testing if PRs are accepted, then I'll continue the work :-)

@Thorium
Copy link
Member Author

Thorium commented Jul 9, 2024

By accepting a dependency to System.Memory in .NET Standard 2.0 (only) we'd get access to .AsSpan() and ReadOnlySpan<_> which could make parsing more efficient in at least .NET Standard 2.1 environment like dotnet.exe and VS Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants