Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/fsharp/vs/Reactor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type internal ReactorCommands =
/// There is one global Reactor for the entire language service, no matter how many projects or files
/// are open.
type Reactor() =
static let pauseBeforeBackgroundWorkDefault = GetEnvInteger "FCS_PauseBeforeBackgroundWorkMilliseconds" 1000
static let pauseBeforeBackgroundWorkDefault = GetEnvInteger "FCS_PauseBeforeBackgroundWorkMilliseconds" 10
static let theReactor = Reactor()
let mutable pauseBeforeBackgroundWork = pauseBeforeBackgroundWorkDefault

Expand Down Expand Up @@ -59,7 +59,11 @@ type Reactor() =
| _, Some _ ->
return! inbox.TryReceive(0)
| Some _, _ ->
let timeout = (if bg then 0 else pauseBeforeBackgroundWork)
let timeout =
if bg then 0
else
Trace.TraceInformation("Reactor: {0:n3} pausing {1} milliseconds", DateTime.Now.TimeOfDay.TotalSeconds, pauseBeforeBackgroundWork)
pauseBeforeBackgroundWork
return! inbox.TryReceive(timeout) }
#if FX_RESHAPED_GLOBALIZATION
CultureInfo.CurrentUICulture <- culture
Expand All @@ -72,7 +76,7 @@ type Reactor() =
return! loop (bgOpOpt, onComplete, false)
| Some (Op (userOpName, opName, opArg, ct, op, ccont)) ->
if ct.IsCancellationRequested then ccont() else
Trace.TraceInformation("Reactor: --> {0}.{1} ({2}), remaining {3}", userOpName, opName, opArg, inbox.CurrentQueueLength)
Trace.TraceInformation("Reactor: {0:n3} --> {1}.{2} ({3}), remaining {4}", DateTime.Now.TimeOfDay.TotalSeconds, userOpName, opName, opArg, inbox.CurrentQueueLength)
let time = Stopwatch()
time.Start()
op ctok
Expand All @@ -81,33 +85,33 @@ type Reactor() =
//if span.TotalMilliseconds > 100.0 then
let taken = span.TotalMilliseconds
let msg = (if taken > 10000.0 then "BAD-OP: >10s " elif taken > 3000.0 then "BAD-OP: >3s " elif taken > 1000.0 then "BAD-OP: > 1s " elif taken > 500.0 then "BAD-OP: >0.5s " else "")
Trace.TraceInformation("Reactor: {0}<-- {1}.{2}, took {3} ms", msg, userOpName, opName, span.TotalMilliseconds)
Trace.TraceInformation("Reactor: {0:n3} {1}<-- {2}.{3}, took {4} ms", DateTime.Now.TimeOfDay.TotalSeconds, msg, userOpName, opName, span.TotalMilliseconds)
return! loop (bgOpOpt, onComplete, false)
| Some (WaitForBackgroundOpCompletion channel) ->
match bgOpOpt with
| None -> ()
| Some (bgUserOpName, bgOpName, bgOpArg, bgOp) ->
Trace.TraceInformation("Reactor: --> wait for background {0}.{1} ({2}), remaining {3}", bgUserOpName, bgOpName, bgOpArg, inbox.CurrentQueueLength)
Trace.TraceInformation("Reactor: {0:n3} --> wait for background {1}.{2} ({3}), remaining {4}", DateTime.Now.TimeOfDay.TotalSeconds, bgUserOpName, bgOpName, bgOpArg, inbox.CurrentQueueLength)
while bgOp ctok do
()
channel.Reply(())
return! loop (None, onComplete, false)
| Some (CompleteAllQueuedOps channel) ->
Trace.TraceInformation("Reactor: --> stop background work and complete all queued ops, remaining {0}", inbox.CurrentQueueLength)
Trace.TraceInformation("Reactor: {0:n3} --> stop background work and complete all queued ops, remaining {1}", DateTime.Now.TimeOfDay.TotalSeconds, inbox.CurrentQueueLength)
return! loop (None, Some channel, false)
| None ->
match bgOpOpt, onComplete with
| _, Some onComplete -> onComplete.Reply()
| Some (bgUserOpName, bgOpName, bgOpArg, bgOp), None ->
Trace.TraceInformation("Reactor: --> background step {0}.{1} ({2})", bgUserOpName, bgOpName, bgOpArg)
Trace.TraceInformation("Reactor: {0:n3} --> background step {1}.{2} ({3})", DateTime.Now.TimeOfDay.TotalSeconds, bgUserOpName, bgOpName, bgOpArg)
let time = Stopwatch()
time.Start()
let res = bgOp ctok
time.Stop()
let taken = time.Elapsed.TotalMilliseconds
//if span.TotalMilliseconds > 100.0 then
let msg = (if taken > 10000.0 then "BAD-BG-SLICE: >10s " elif taken > 3000.0 then "BAD-BG-SLICE: >3s " elif taken > 1000.0 then "BAD-BG-SLICE: > 1s " else "")
Trace.TraceInformation("Reactor: {0}<-- background step, took {1}ms", msg, taken)
Trace.TraceInformation("Reactor: {0:n3} {1}<-- background step, took {2}ms", DateTime.Now.TimeOfDay.TotalSeconds, msg, taken)
return! loop ((if res then bgOpOpt else None), onComplete, true)
| None, None -> failwith "unreachable, should have used inbox.Receive"
}
Expand All @@ -121,28 +125,28 @@ type Reactor() =

// [Foreground Mailbox Accessors] -----------------------------------------------------------
member r.SetBackgroundOp(bgOpOpt) =
Trace.TraceInformation("Reactor: enqueue start background, length {0}", builder.CurrentQueueLength)
Trace.TraceInformation("Reactor: {0:n3} enqueue start background, length {1}", DateTime.Now.TimeOfDay.TotalSeconds, builder.CurrentQueueLength)
builder.Post(SetBackgroundOp bgOpOpt)

member r.EnqueueOp(userOpName, opName, opArg, op) =
Trace.TraceInformation("Reactor: enqueue {0}.{1} ({2}), length {3}", userOpName, opName, opArg, builder.CurrentQueueLength)
Trace.TraceInformation("Reactor: {0:n3} enqueue {1}.{2} ({3}), length {4}", DateTime.Now.TimeOfDay.TotalSeconds, userOpName, opName, opArg, builder.CurrentQueueLength)
builder.Post(Op(userOpName, opName, opArg, CancellationToken.None, op, (fun () -> ())))

member r.EnqueueOpPrim(userOpName, opName, opArg, ct, op, ccont) =
Trace.TraceInformation("Reactor: enqueue {0}.{1} ({2}), length {3}", userOpName, opName, opArg, builder.CurrentQueueLength)
Trace.TraceInformation("Reactor: {0:n3} enqueue {1}.{2} ({3}), length {4}", DateTime.Now.TimeOfDay.TotalSeconds, userOpName, opName, opArg, builder.CurrentQueueLength)
builder.Post(Op(userOpName, opName, opArg, ct, op, ccont))

member r.CurrentQueueLength =
builder.CurrentQueueLength

// This is for testing only
member r.WaitForBackgroundOpCompletion() =
Trace.TraceInformation("Reactor: enqueue wait for background, length {0}", builder.CurrentQueueLength)
Trace.TraceInformation("Reactor: {0:n3} enqueue wait for background, length {0}", DateTime.Now.TimeOfDay.TotalSeconds, builder.CurrentQueueLength)
builder.PostAndReply WaitForBackgroundOpCompletion

// This is for testing only
member r.CompleteAllQueuedOps() =
Trace.TraceInformation("Reactor: enqueue wait for all ops, length {0}", builder.CurrentQueueLength)
Trace.TraceInformation("Reactor: {0:n3} enqueue wait for all ops, length {0}", DateTime.Now.TimeOfDay.TotalSeconds, builder.CurrentQueueLength)
builder.PostAndReply CompleteAllQueuedOps

member r.EnqueueAndAwaitOpAsync (userOpName, opName, opArg, f) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Microsoft.VisualStudio.FSharp.Editor

open System
open System.Composition
open System.Collections.Generic
open System.Diagnostics
open System.Threading

open Microsoft.CodeAnalysis
Expand Down Expand Up @@ -36,6 +38,7 @@ type internal FSharpColorizationService

member this.AddSemanticClassificationsAsync(document: Document, textSpan: TextSpan, result: List<ClassifiedSpan>, cancellationToken: CancellationToken) =
asyncMaybe {
do Trace.TraceInformation("{0:n3} (start) SemanticColorization", DateTime.Now.TimeOfDay.TotalSeconds)
do! Async.Sleep DefaultTuning.SemanticColorizationInitialDelay |> liftAsync // be less intrusive, give other work priority most of the time
let! options = projectInfoManager.TryGetOptionsForDocumentOrProject(document)
let! sourceText = document.GetTextAsync(cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace rec Microsoft.VisualStudio.FSharp.Editor

open System
open System.Collections.Immutable
open System.Diagnostics
open System.Threading
open System.Threading.Tasks
open System.Runtime.CompilerServices
Expand All @@ -18,7 +19,8 @@ open Microsoft.VisualStudio.FSharp.LanguageService

type private TextVersionHash = int

[<DiagnosticAnalyzer(FSharpConstants.FSharpLanguageName)>]
// Disable until we work out how to make this low priority
//[<DiagnosticAnalyzer(FSharpConstants.FSharpLanguageName)>]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

;-(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I know. But I feel it's the right thing to do until we get really authoritative information on dotnet/roslyn#20390

SimplifyName is different to the other analyzers in that it makes many requests to FCS - one for each identifier

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This analyzer has a setting that we can make off by default instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vasily-kirichenko ok, thanks, I will submit a follow-up PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

type internal SimplifyNameDiagnosticAnalyzer() =
inherit DocumentDiagnosticAnalyzer()

Expand Down Expand Up @@ -47,6 +49,7 @@ type internal SimplifyNameDiagnosticAnalyzer() =

override this.AnalyzeSemanticsAsync(document: Document, cancellationToken: CancellationToken) =
asyncMaybe {
do Trace.TraceInformation("{0:n3} (start) SimplifyName", DateTime.Now.TimeOfDay.TotalSeconds)
do! Async.Sleep DefaultTuning.SimplifyNameInitialDelay |> liftAsync
do! Option.guard Settings.CodeFixes.SimplifyName
let! options = getProjectInfoManager(document).TryGetOptionsForEditingDocumentOrProject(document)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace rec Microsoft.VisualStudio.FSharp.Editor

open System
open System.Collections.Generic
open System.Collections.Immutable
open System.Diagnostics
open System.Threading.Tasks
open System.Collections.Generic

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Diagnostics
Expand Down Expand Up @@ -99,6 +100,7 @@ type internal UnusedDeclarationsAnalyzer() =

override __.AnalyzeSemanticsAsync(document, cancellationToken) =
asyncMaybe {
do Trace.TraceInformation("{0:n3} (start) UnusedDeclarationsAnalyzer", DateTime.Now.TimeOfDay.TotalSeconds)
do! Async.Sleep DefaultTuning.UnusedDeclarationsAnalyzerInitialDelay |> liftAsync // be less intrusive, give other work priority most of the time
match getProjectInfoManager(document).TryGetOptionsForEditingDocumentOrProject(document) with
| Some options ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor

open System
open System.Collections.Immutable
open System.Diagnostics
open System.Threading
open System.Threading.Tasks

Expand Down Expand Up @@ -170,6 +171,7 @@ type internal UnusedOpensDiagnosticAnalyzer() =

override this.AnalyzeSemanticsAsync(document: Document, cancellationToken: CancellationToken) =
asyncMaybe {
do Trace.TraceInformation("{0:n3} (start) UnusedOpensAnalyzer", DateTime.Now.TimeOfDay.TotalSeconds)
do! Async.Sleep DefaultTuning.UnusedOpensAnalyzerInitialDelay |> liftAsync // be less intrusive, give other work priority most of the time
let! options = getProjectInfoManager(document).TryGetOptionsForEditingDocumentOrProject(document)
let! sourceText = document.GetTextAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type internal FSharpCheckerProvider
let solution = workspace.CurrentSolution
let documentIds = solution.GetDocumentIdsWithFilePath(fileName)
if not documentIds.IsEmpty then
for documentId in documentIds do
Trace.TraceInformation("Requesting Roslyn reanalysis of {0}", documentId)
analyzerService.Reanalyze(workspace,documentIds=documentIds)
| _ -> ()
with ex ->
Expand Down Expand Up @@ -446,6 +448,7 @@ and
for referencedSite in ProjectSitesAndFiles.GetReferencedProjectSites (site, this.SystemServiceProvider) do
let referencedProjectId = setup referencedSite
project.AddProjectReference(ProjectReference referencedProjectId)
workspace.ProjectTracker.AddProject(project)
projectId
setup (siteProvider.GetProjectSite()) |> ignore

Expand Down
4 changes: 2 additions & 2 deletions vsintegration/src/FSharp.Editor/Options/EditorOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ open OptionsUIHelpers

module DefaultTuning =
let SemanticColorizationInitialDelay = 0 (* milliseconds *)
let UnusedDeclarationsAnalyzerInitialDelay = 1000 (* milliseconds *)
let UnusedOpensAnalyzerInitialDelay = 2000 (* milliseconds *)
let UnusedDeclarationsAnalyzerInitialDelay = 0 (* 1000 *) (* milliseconds *)
let UnusedOpensAnalyzerInitialDelay = 0 (* 2000 *) (* milliseconds *)
let SimplifyNameInitialDelay = 2000 (* milliseconds *)
let SimplifyNameEachItemDelay = 5 (* milliseconds *)

Expand Down