dotnet / dotnet/fsharp

isOpenStatementUsed uses a lot of CPU and memory

Open
#9,230 0 comments 1 reaction 1 assignee Claimed by @psfinaki View on GitHub
Area-LangService-UnusedOpens Feature Request Theme-Performance
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

I collected a trace after about an hour of working in VisualFSharp.sln when memory was pretty high. I found that the [`isOpenStatementUsed` function](https://github.com/dotnet/fsharp/blob/master/src/fsharp/service/ServiceAnalysis.fs#L147) is pretty expensive relative to other things.

10.8% of all allocations in the sample (533MB):

![image](https://user-images.githubusercontent.com/6309070/82243370-54c72180-98f4-11ea-91c5-8cc887ba198b.png)

And 6.3% of total CPU time:

![image](https://user-images.githubusercontent.com/6309070/82243433-71fbf000-98f4-11ea-95f3-13b7b79608ef.png)

This is because the routine does a very expensive list operation where it scans a document's symbols to check if a given open statement is responsible for those symbols (i.e., if the open statement can be removed or not).

This isn't really a big deal with small files, but for large ones (like in the compiler codebase), it bubbles up to the top like this.

Unfortunately, there doesn't seem to be an easy win here. Making this better will likely mean rewriting how we determine if an open declaration is in use.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.