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

[WIP] fsc.exe - Parallel Parsing #10208

Closed
wants to merge 2 commits into from
Closed

Conversation

TIHan
Copy link
Contributor

@TIHan TIHan commented Oct 2, 2020

This enables parallel parsing when running fsc.exe. I think this should be fairly straight forward to make safe.

results.[i] <-
let (filename: string, isLastCompiland) = sourceFiles.[i]
let pathOfMetaCommandSource = Path.GetDirectoryName filename
match ParseOneInputFile(tcConfig, lexResourceManager, ["COMPILED"], filename, (isLastCompiland, isExe), errorLogger, (*retryLocked*)false) with
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The errorLogger is probably not concurrent safe; will need to solve that.

@cartermp
Copy link
Contributor

cartermp commented Oct 2, 2020

How does this stack up in benchmarks?

src/fsharp/fsc.fs Outdated Show resolved Hide resolved
Co-authored-by: Saul Rennison <saul@users.noreply.github.com>
@TIHan
Copy link
Contributor Author

TIHan commented Oct 2, 2020

I will get some benchmarks soon. My gut feel is that it will only shave a few seconds off of compiling the compiler as an example.

@TIHan TIHan linked an issue Oct 2, 2020 that may be closed by this pull request
@En3Tho
Copy link
Contributor

En3Tho commented Oct 13, 2020

This optimization will benefit fcs the most i believe, not fsc. IDE's like VS, Rider already can build stuff really quickly with heuristics and so on, but while working with code fcs is a thing that takes too much time. Can this optimization be turned on for fcs?

@auduchinok
Copy link
Member

auduchinok commented Oct 13, 2020

@En3Tho F# parsing is usually not a problem in IDEs. To make IDE work faster we need optimizations for type-checking, which is a subsequent phase after the parsing one. Moreover, FCS keeps only few file parsing results in its cache to save memory, so there's no need to parse files until they're needed by type checker or some IDE feature (and type checker doesn't run in parallel anyway).

Previously parsing would wait in the FCS queue if there's a long type checking process, and it has been improved in #3601, now IDE features are already allowed to parse files in parallel.

@En3Tho
Copy link
Contributor

En3Tho commented Oct 13, 2020

@auduchinok @TIHan Thank you for an answer. Any plans to further parallelize compiler stages? It feels quite sad to wait for fcs every time while having 8/16 core/threads processor and 64 gigs of mem

@cartermp
Copy link
Contributor

No current plans, but @TIHan has looked into it before. It should be possible in theory without having to rewrite everything, but it won't be easy

@TIHan
Copy link
Contributor Author

TIHan commented Oct 13, 2020

@auduchinok is right. Type-checking is where almost all the time is spent. Parsing is really fast in F# - I'm not even sure if parallel parsing files will give us that much benefit (haven't made benchmarks yet).

@En3Tho, @dsyme and I discussed parallel type-checking in FCS last week. We went over a variety of things, and it should be possible. However, specifically in VS, parallelism could make things worse as more objects can be allocated at one time.

When I did the compiler server prototype, I made a lot of fixes that supported the work being done in parallel, such as forcing all type provider calls on the same thread. Perhaps I can re-use some of that work and make small PRs that will inch our way towards parallelism.

Another idea that's interesting is parallel type-checking when compiling: #10214

--

The caveat here with parallelism is that the compiler has not been fully proven to be safe in parallel at certain stages. So, what we really need to do is design for correctness first over speed.

@cartermp
Copy link
Contributor

cartermp commented Oct 13, 2020

I'm not even sure if parallel parsing files will give us that much benefit (haven't made benchmarks yet).

I imagine it would help parsing our FSharp.Core test suite, since other threads could parse stuff while one is working on this chonky boi: https://github.com/dotnet/fsharp/blob/main/tests/FSharp.Core.UnitTests/FSharp.Core/ComparersRegression.fs

@KevinRansom
Copy link
Member

@TIHan , it looks like you are not convinced about the performance benefits of this change: #10208 (comment). So I will close it, please reactivate the issue if you change your mind and get an opportunity to develope it further.

Thanks

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.

fsc.exe - Parallel Parsing
6 participants