Skip to content

TransparentCompiler ignores keepAllBackgroundSymbolUses and enableBackgroundItemKeyStoreAndSemanticClassification, and caches every file's name resolution sink #20755

Open

Description

@nojaf

FSharpChecker.Create takes three options that decide how much of a background check the background compiler keeps. The transparent compiler stores two of them and never reads them, and reads the third for one field only:

  • keepAllBackgroundSymbolUses and enableBackgroundItemKeyStoreAndSemanticClassification are constructor parameters (L418-L419) and have no other use in TransparentCompiler.fs.
  • keepAllBackgroundResolutions only picks tcEnvAtEndOfFile (L1489).

ComputeTcIntermediate always creates a TcResultsSinkImpl (L1423) and keeps it in the TcIntermediate it caches (L79-L92). So every file that was type checked, also the files that were only checked because a later file depends on them, keeps all its name resolutions for as long as its TcIntermediate is cached. ComputeParseAndCheckAllFilesInProject also collects the sinks of all files of the project (collectSinks = true, L1758), and that is the path that produces the assembly data of an in-memory project reference.

With the background compiler, keepAllBackgroundResolutions = false and keepAllBackgroundSymbolUses = false drop the resolutions and symbol uses of the files it checked in the background.

Measured

FsAutoComplete with FCS 43.12.201, transparent compiler, default cache sizes, on the Fantomas solution. Session: open two files of Fantomas.Core, hover and navigate, then one Find References on SyntaxOak.Expr (672 references in 9 files). Dominator tree of a heap dump taken at the end:

Retained
Live heap 689 MB
CompilerCaches 386 MB
TcIntermediate cache, 108 entries 73 MB
The 108 TcResultsSinkImpl in those entries 34 MB

The same session with the options turned off in FsAutoComplete, one run each:

Options RSS after Find References
All three true (FsAutoComplete's default) 1,112 MB
keepAllBackgroundResolutions = false 1,117 MB
keepAllBackgroundSymbolUses = false, enableBackgroundItemKeyStoreAndSemanticClassification = false 1,134 MB

Run-to-run noise is about ±25 MB, so none of them changes anything. The links above point to main; 43.12.201 has the same code in these places.

Proposal

  • Honour keepAllBackgroundSymbolUses = false in ComputeParseAndCheckAllFilesInProject: do not collect the sinks. The background compiler does not keep the symbol uses either.
  • Honour keepAllBackgroundResolutions = false: keep the sink only for the file that was asked for. ComputeTcLastFile only uses the sink of the last file, so the TcIntermediate of the files before it does not need one. The cost is that opening one of those files later type checks it again, as with the background compiler.
  • enableBackgroundItemKeyStoreAndSemanticClassification: the transparent compiler builds both on demand from the sink, so the option means nothing there. Say so in its XML doc.

Expected gain: up to the 34 MB above for this session, more where in-memory project references are type checked for their assembly data. I have not measured that case.

Related: #8021 (the same data structure in the background compiler).

Activity

  1. added this to the Backlog milestone on Oct 10, 2026
  2. added
    Area-Compiler-Service
    and removed on Oct 12, 2026
  3. T-Gro commented on Oct 12, 2026

    @T-Gro
    Member

    Can you pls include how the switches are used in the popular users (FsAutoComplete, Fantomas, ..) ? For the second proposal.

    The first and third proposals are good as they are 👍

  4. nojaf commented on Oct 12, 2026

    @nojaf
    ContributorAuthor

    Usage of the three switches in the main consumers:

    • VS: keepAllBackgroundResolutions = false and keepAllBackgroundSymbolUses = false by default (user settings in EditorOptions.fs), enableBackgroundItemKeyStoreAndSemanticClassification = true. The transparent compiler is opt-in (UseTransparentCompiler = false by default).
    • FsAutoComplete: all three true. The transparent compiler is opt-in.
    • Rider: keepAllBackgroundResolutions = false and keepAllBackgroundSymbolUses = false (FcsCheckerService.fs). It uses the background compiler, on the JetBrains fork of FCS.
    • FSharp.Analyzers.SDK: keepAllBackgroundResolutions = true, background compiler.
    • Fantomas: not a consumer for this use-case.

    None of them call GetBackgroundCheckResultsForFileInProject. VS calls ParseAndCheckProject in GoToDefinition.fs, but reads only AssemblySignature from the result.

    So today the second proposal changes behaviour only for VS with the transparent compiler on. There it brings the transparent compiler in line with what VS already gets from the background compiler. FsAutoComplete would switch to false once the transparent compiler honours it: it already asks for every file it needs through ParseAndCheckFileInProject.

    @auduchinok, any ideas what Rider would do here in the (near?) future? Rider passes false for both options, so it would get this behaviour as soon as it switches.

  5. auduchinok commented on Oct 28, 2026

    @auduchinok
    Member

    @auduchinok, any ideas what Rider would do here in the (near?) future? Rider passes false for both options, so it would get this behaviour as soon as it switches.

    Do you mean the switch the transparent compiler? @DedSec256 is working on it now. 🙂

  6. nojaf commented on Oct 28, 2026

    @nojaf
    ContributorAuthor

    @auduchinok, yes, what are you folks doing with keepAllBackgroundSymbolUses and enableBackgroundItemKeyStoreAndSemanticClassification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-ServiceFeature ImprovementTheme-Performance

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions