You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/queue.fsx
+30-34Lines changed: 30 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -6,21 +6,22 @@ Compiler Services: Notes on the FSharpChecker operations queue
6
6
7
7
This is a design note on the FSharpChecker component and its operations queue. See also the notes on the [FSharpChecker caches](caches.html)
8
8
9
-
FSharpChecker maintains an operations queue. Items from the FSharpChecker operations queue are currently processed
9
+
FSharpChecker maintains an operations queue. Items from the FSharpChecker operations queue are processed
10
10
sequentially and in order.
11
11
12
-
In addition to operations in the queue, there is also a low-priority, interleaved background operation
13
-
to bring the checking of the checking of "the current background project" up-to-date. When the queue is empty
14
-
this operation is conducted in small incremental fragments of parse/check work (cooperatively time-sliced to be approximately <50ms,
15
-
see `maxTimeShareMilliseconds` in IncrementalBuild.fs). For a working definition of "current background project"
16
-
you currently have to see the calls to `StartBackgroundCompile`
17
-
in [service.fs](https://github.com/fsharp/FSharp.Compiler.Service/blob/master/src/fsharp/vs/service.fs),
18
-
where an API call which in turn calls StartBackgroundCompile indicates that the current background project has been specified.
12
+
The thread processing these requests can also run a low-priority, interleaved background operation when the
13
+
queue is empty. This can be used to implicitly bring the background check of a project "up-to-date".
14
+
When the operations queue has been empty for 1 second,
15
+
this background work is run in small incremental fragments. This work is cooperatively time-sliced to be approximately <50ms, (see `maxTimeShareMilliseconds` in
16
+
IncrementalBuild.fs). The project to be checked in the background is set implicitly
17
+
by calls to ``CheckFileInProject`` and ``ParseAndCheckFileInProject``.
18
+
To disable implicit background checking completely, set ``checker.ImplicitlyStartBackgroundWork`` to false.
19
+
To change the time before background work starts, set ``checker.PauseBeforeBackgroundWork`` to the required number of milliseconds.
19
20
20
-
Many calls to the FSharpChecker API enqueue an operation in the FSharpChecker compiler queue. These correspond to the
21
+
Most calls to the FSharpChecker API enqueue an operation in the FSharpChecker compiler queue. These correspond to the
21
22
calls to EnqueueAndAwaitOpAsync in [service.fs](https://github.com/fsharp/FSharp.Compiler.Service/blob/master/src/fsharp/vs/service.fs).
22
23
23
-
* For example, calling `ParseAndCheckProject` enqueues a `ParseAndCheckProjectImpl` operation. The length of the
24
+
* For example, calling `ParseAndCheckProject` enqueues a `ParseAndCheckProjectImpl` operation. The time taken for the
24
25
operation will depend on how much work is required to bring the project analysis up-to-date.
25
26
26
27
* Likewise, calling any of `GetUsesOfSymbol`, `GetAllUsesOfAllSymbols`, `ParseFileInProject`,
@@ -30,30 +31,25 @@ calls to EnqueueAndAwaitOpAsync in [service.fs](https://github.com/fsharp/FSharp
30
31
vary - many will be very fast - but they won't be processed until other operations already in the queue are complete.
31
32
32
33
Some operations do not enqueue anything on the FSharpChecker operations queue - notably any accesses to the Symbol APIs.
33
-
These are multi-threaded access to the TAST data produced by other FSharpChecker operations.
34
-
35
-
In advanced interactive scenarios you may need to consider contributing design changes and extensions to how the FSharpChecker queue works,
36
-
in order to better serve your needs. Some tools throw a lot of interactive work at the FSharpChecker operations queue.
37
-
If you are writing such a component, we encourage you to get more involved in making carefully considered
38
-
changes, cleanup and documentation to how the queue works, to ensure it is suitable for your needs.
39
-
40
-
For example, from the FCS point of view, it is plausible to consider changing of extending how the
41
-
FSharpChecker operations queue works - the design of the queue and its processing is not sacred.
42
-
In theory you could submit extensions and documentation that allow prioritization of operations, or interleaving of
43
-
operations, or cancellation of operations, or more explicitness about the "current background project", and so on.
44
-
45
-
Finally, for those writing interactive editors which use FCS, in the current state of affairs you
46
-
should be cautious about having any auto-operation (e.g. operations like "Find Unused Declarations"
47
-
which run automatically and are unassociated with a user action, but not operations like "Find All References"
48
-
which a user explicitly triggers) request a check of the entire project. That will cause very long operations
49
-
and contention on the FSharpChecker operations queue. Any such very-long-running request should normally be associated
50
-
with a user action, and preferably it should be cancellable.
51
-
52
-
Alternatively, it is reasonable to trigger these
53
-
kinds of auto-operations when the ProjectChecked event is triggered on FSharpChecker. This event indicates the
54
-
completion of interleaved checking of the "current background project" (specified above). Again, if
55
-
the spec of "current background project" is not suitable or sufficiently controlled for your needs, please
56
-
help to document it and adjust it.
34
+
These use cross-threaded access to the TAST data produced by other FSharpChecker operations.
35
+
36
+
Some tools throw a lot of interactive work at the FSharpChecker operations queue.
37
+
If you are writing such a component, consider running your project against a debug build
38
+
of FSharp.Compiler.Service.dll to see the Trace.WriteInformation messages indicating the length of the
39
+
operations queuea and the time to process requests.
40
+
41
+
For those writing interactive editors which use FCS, you
42
+
should be cautious about operations that request a check of the entire project.
43
+
For example, be careful about requesting the check of an entire project
44
+
on operations like "Highlight Symbol" or "Find Unused Declarations"
45
+
(which run automatically when the user opens a file or moves the cursor).
46
+
as opposed to operations like "Find All References" (which a user explicitly triggers).
47
+
Project checking can cause long and contention on the FSharpChecker operations queue.
48
+
49
+
Requests to FCS can be cancelled by cancelling the async operation. (Some requests also
50
+
include additional callbacks which can be used to indicate a cancellation condition).
51
+
This cancellation will be effective if the cancellation is performed before the operation
0 commit comments