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

A few super-minor compiler perf improvements #17130

Merged
merged 8 commits into from May 13, 2024

Conversation

brianrourkeboll
Copy link
Contributor

@brianrourkeboll brianrourkeboll commented May 9, 2024

Description

I saw some of these show up when I did a quick profile of FSharp.Compiler.ComponentTests, which take the longest to run of all the tests.

  • Override ToString on BuildPhase; the automatic printf-based implementation does a lot more work than it needs to for a fieldless DU.

    Example DiagnosticsLogger_BuildPhase_ToString_Screenshot 2024-05-09 110559_2

    let ParseInput
    (
    lexer,
    diagnosticOptions: FSharpDiagnosticOptions,
    diagnosticsLogger: DiagnosticsLogger,
    lexbuf: UnicodeLexing.Lexbuf,
    defaultNamespace,
    fileName,
    isLastCompiland,
    identCapture,
    userOpName
    ) =
    use _ =
    Activity.start
    "ParseAndCheckFile.parseFile"
    [|
    Activity.Tags.fileName, fileName
    Activity.Tags.buildPhase, BuildPhase.Parse.ToString()

    I guess I could have just changed the above to this instead:

    -Activity.Tags.buildPhase, BuildPhase.Parse.ToString()
    +Activity.Tags.buildPhase, nameof BuildPhase.Parse

    But maybe it's best to speed up any potential future stringifications anyway, just in case.

  • Cache the delegate passed into ConcurrentDictionary.GetOrAdd where possible. See Cache delegates #14582, Emit direct delegates when possible fsharp/fslang-suggestions#1083, etc.

  • Remove a redundant StringBuilder in one place.

Checklist

  • Release notes entry updated.

* Override `ToString` on `BuildPhase`.

* Cache the delegate passed into `ConcurrentDictionary.GetOrAdd` where
  possible. See dotnet#14582, fsharp/fslang-suggestions#1083, etc.
Copy link
Contributor

github-actions bot commented May 9, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/FSharp.Core docs/release-notes/.FSharp.Core/8.0.400.md
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.400.md

@brianrourkeboll brianrourkeboll marked this pull request as ready for review May 9, 2024 23:48
@brianrourkeboll brianrourkeboll requested a review from a team as a code owner May 9, 2024 23:48
* I don't think I fully understand why, but I did some rough
  microbenchmarking, and for some reason the `GetOrAdd` and
  `Interlocked.Increment` on a ref cell technique is actually something
  like twice as fast as `AddOrUpdate`.
Copy link
Member

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

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

Thanks!

@psfinaki psfinaki enabled auto-merge (squash) May 13, 2024 11:05
@psfinaki psfinaki merged commit 75c3558 into dotnet:main May 13, 2024
32 checks passed
@brianrourkeboll brianrourkeboll deleted the minor-perf-improvements branch May 13, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants