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

Reduce project option duplication, reducing memory usage. #1147

Merged
merged 1 commit into from
Jul 22, 2023

Conversation

TheAngryByrd
Copy link
Member

@TheAngryByrd TheAngryByrd commented Jul 22, 2023

WHAT

🤖 Generated by Copilot at 08fadc8

Improved project and script loading to handle multi-targeting scenarios. Replaced the LoadedProject discriminated union with a simpler record type. Refactored loadProject in AdaptiveFSharpLspServer.fs to use the new type and logic.

🤖 Generated by Copilot at 08fadc8

LoadedProject changed
Multi-targeting scripts now
Simpler type, no waste

🔄📝🚀

WHY

I noticed we were creating way to many project options.

Screenshot 2023-07-21 154750

After the change it doesn't really show up now.

Screenshot 2023-07-21 154859

HOW

🤖 Generated by Copilot at 08fadc8

  • Refactor LoadedProject type to use a record with custom equality instead of a union of LoadedProjectFile and LoadedScriptFile (link)
  • Use FCS.mapManyOptions to handle multiple project options per file and support multi-targeting projects and scripts (link, link, link, link)
  • Use ProjectFileName property of FSharpProjectOptions instead of ProjectOptions to avoid null values for scripts (link)
  • Remove unused LoadedScriptFile case from LoadedProject type (link)

Comment on lines +63 to +77
[<CustomEquality; NoComparison>]
type LoadedProject =
{ FSharpProjectOptions: FSharpProjectOptions
LanguageVersion: LanguageVersionShim }

type LoadedProject =
| LoadedProjectFile of LoadedProjectFile
| LoadedScriptFile of LoadedScriptFile
interface IEquatable<LoadedProject> with
member x.Equals(other) =
x.FSharpProjectOptions = other.FSharpProjectOptions

member x.FSharpProjectOptions =
match x with
| LoadedProjectFile p -> p.FSharpProjectOptions
| LoadedScriptFile p -> p.FSharpProjectOptions
override x.GetHashCode() = x.FSharpProjectOptions.GetHashCode()

member x.LanguageVersion =
match x with
| LoadedProjectFile p -> p.LanguageVersion
| LoadedScriptFile p -> p.LanguageVersion
override x.Equals(other) =
match other with
| :? LoadedProject as other -> (x :> IEquatable<_>).Equals other
| _ -> false
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't really need to keep ProjectOptions so condensing this type. Also makes it use FSharpProjectOptions as its equality.

projectOptions
|> List.map (fun o ->
let fso = FCS.mapToFSharpProjectOptions o projectOptions
let fsharpOptions = projectOptions |> FCS.mapManyOptions |> Seq.toList
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main change. We had this in Ionide.ProjInfo but weren't using it. This prevent recreation of referenced types.

@TheAngryByrd TheAngryByrd force-pushed the fix-projectOptions-memory-usage branch from 08fadc8 to c527897 Compare July 22, 2023 01:35
Copy link
Contributor

@baronfel baronfel left a comment

Choose a reason for hiding this comment

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

Heck yeah

@TheAngryByrd TheAngryByrd merged commit d830466 into main Jul 22, 2023
8 of 9 checks passed
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.

2 participants