Skip to content

perf(#r "paket:"): look for dotnet once and run dotnet nuget locals once per folder, without waiting for an output left open - #4499

Merged
fpellet merged 5 commits into
masterfrom
perf/fsi-dotnet-once
Nov 22, 2026
Merged

fpellet merged 5 commits into
masterfrom
perf/fsi-dotnet-once

Conversation

@fpellet

@fpellet fpellet commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Follows #4498, whose fallback it speeds up.

Problem

When the tool manifest declares paket but its local tool isn't restored, and no global tool is installed, #r "paket:" ran dotnet nuget locals global-packages --list twice without NUGET_PACKAGES: in the folder of the manifest, to look for the local tool, and in the folder of the script, for the most recent Paket .NET tool restored. They are often the same folder (build.fsx next to .config). With an SDK that hangs, the script waited 30 seconds twice before running Paket or failing.

The dotnets that exist were also listed each time one was needed: once to run the paket.dll, and once for each dotnet nuget locals, which also picked the one with an SDK each time.

The command read its whole output, and waited 5 more seconds for its end after dotnet exited. A process that dotnet left running and that keeps the output open made a run that printed its folder count as a timeout: the folder was lost, no other folder was asked, and a local tool restored in the globalPackagesFolder of a nuget.config was reported as not restored. The output of a dotnet that failed was waited for too, only to be discarded. And a dotnet that printed its folder and then hung on exit lost that folder.

Change

During one resolution of the #r "paket:" lines of a script:

  • the dotnets that exist are looked for once, when one is needed, and shared by the pick of the dotnet that runs the paket.dll and the pick of the dotnet with an SDK, which is made once;
  • dotnet nuget locals runs at most once per folder. The folder of the script is the DirectoryInfo that findLocalTool walks up from, so that a manifest for that folder gives the same string. When dotnet doesn't exit within 30 seconds, the command doesn't run again for the other folder, which then only has ~/.nuget/packages.

Internals.Logic.nugetPackagesFolderOnce keeps the answers of a resolution; nugetPackagesFolder tells a timeout (TimedOut) apart from a folder that dotnet doesn't give (Known None).

Internals.Logic.runNuGetLocals runs the command, with its timeouts as parameters:

  • the folder is taken from its line as it comes, without waiting for the end of the output;
  • the output of a dotnet that failed is discarded without waiting for its end;
  • a dotnet that exited didn't hang: when no folder line comes within 5 seconds after it exits, it gives Known None, and the next folder is still asked. Only a dotnet that doesn't exit within 30 seconds gives TimedOut: it is killed with its process tree, and the folder that it printed until then, if any, is kept;
  • on Windows, where Process.Kill(true) still finds the running child processes of an exited process from its handle, the end of the output is waited for within 5 seconds after dotnet exits in all, and what keeps it open is then killed. On Linux and macOS, .NET no longer looks for them once the process exited, and .NET Framework has no Kill(true): what dotnet left running stays, as before;
  • on .NET Framework, Path.IsPathRooted throws on quotes: a line is now read in the output handler, where the exception would end F# Interactive, so such a folder is left out.

Docs: fsi-integration.md says when only ~/.nuget/packages is looked at, that a dotnet stopped after 30 seconds keeps the folder it gave, and that the command runs at most once per folder. No release note: the dotnet lookup (#4496), dotnet nuget locals (#4497) and the fallback (#4498) all came after 12.0.0, and their Unreleased lines stay true.

Commits:

  1. look for dotnet once;
  2. run dotnet nuget locals at most once per folder, with nugetPackagesFolderOnce, its tests and the docs;
  3. don't wait for an output of dotnet nuget locals that it left open: runNuGetLocals, and its tests on a stand-in dotnet;
  4. kill on Windows what keeps the output of an exited dotnet nuget locals open;
  5. keep the folder that a dotnet nuget locals gave before it timed out.

Tests

tests/Paket.Tests/FsiExtension.fs tests:

  • nugetPackagesFolderOnce: one run per folder, also when dotnet gives no folder, which doesn't stop the next folder; no run after a timeout; a folder told before a timeout keeps its answer; and the folder of the run that timed out is kept.
  • runNuGetLocals, on a stand-in dotnet, a /bin/sh script that can leave a sleep running with the output open: the folder of the output, also at once when the output stays open; no folder after a failure, without waiting for an output left open; a timeout that kills the process tree, and keeps the folder printed before it; no timeout for a dotnet that exits with its output left open; the end of the output, which stops the wait; and, with killsLeftOver, the wait of 5 seconds in all after the exit. These tests are ignored on Windows, and on Linux the killsLeftOver ones can only check the elapsed time, since nothing is killed there.

Checked by hand on Linux with the first two commits, SDK 10.0.404 and dotnet fsi --compilertool: pointing at the built extension, with a manifest that declares a paket that isn't restored, a fresh HOME and DOTNET_CLI_HOME, no NUGET_PACKAGES, and DOTNET_HOST_PATH pointing at a dotnet script that logs its calls, next to the sdk, host and shared folders of the install:

  • script next to .config: one dotnet nuget locals;
  • script in a subfolder: one per folder, the one of the manifest and the one of the script;
  • script in a subfolder, with a dotnet nuget locals that sleeps 45 s: one call, killed after 30 s, and the whole run, ending with the "not restored" error, took 32 s.

The wiring has no automated test: the single lookup of the dotnets, the memo shared by the lookup of the local tool and the one of the most recent Paket, and the same string for the folder of the script. That needs an F# Interactive integration test with a manifest that isn't restored, which #4498 lacks too.

Limits

  • After a timeout in the folder of the manifest, the folder of the script isn't asked, even when it has a global.json of its own that picks a working SDK: the most recent Paket .NET tool is then only looked for in ~/.nuget/packages. The same dotnet runs in both folders, and a hang there is unlikely to depend on the folder.
  • The answers last one resolution: an SDK that hangs still costs 30 seconds at each resolution. That happens each time the #r lines change, and on every run of the script while the local tool isn't restored, as fix(#r "paket:"): fall back when the local tool isn't restored #4498 resolves again after a failure or after a Paket that ran in its place.
  • On Windows, Kill(true) doesn't find a process started by a process that already exited, as the one of NuGet that dotnet nuget starts: the 5 seconds are then waited for nothing, for each folder. A Job Object, or a process group on Linux and macOS, would reach it, with P/Invoke.
  • On Linux and macOS, a dotnet that exits without a folder line while what it left running keeps the output open gives no folder after 5 seconds, for each folder, and what it left running isn't killed.
  • runNuGetLocals has no test on Windows, the only OS where it kills after the exit: the stand-in dotnet is a shell script.

A resolution listed the dotnets that exist to run a paket.dll, and
again each time it asked dotnet for the NuGet packages folder, where it
also picked the dotnet with an SDK each time. List them once, when one
is needed, checking that a dotnet exists only when a pick reaches it,
and pick the dotnet with an SDK once.
When the local tool isn't restored and no global tool is installed,
#r "paket:" ran `dotnet nuget locals` for the folder of the manifest and
then for the folder of the script, often the same, and an SDK that hangs
made the script wait 30 seconds twice. Ask at most once per folder
during a resolution, and in no other folder after a run that timed out,
as the same dotnet would hang again: the most recent Paket .NET tool is
then only looked for in ~/.nuget/packages.

The folder of the script is the DirectoryInfo that findLocalTool walks
up from, so that a manifest for that folder gives the same string; the
lookup of a --tool-path paket walks up from it too.
…n in #r "paket:"

A process that dotnet left running keeps its output open after it exits:
#r "paket:" waited 5 more seconds for the end of that output, then took the
run for one that timed out, without its folder, and asked no other folder.
The folder is now taken from its line as it comes, the output of a dotnet
that failed isn't waited for, and only a dotnet that doesn't exit within 30
seconds stops the other folders: a dotnet that exited didn't hang.

The command runs in Internals.Logic.runNuGetLocals, with its timeouts as
parameters, which the tests run on a stand-in dotnet, a sh script. On .NET
Framework, IsPathRooted throws on quotes: the folder of a line is now read
in the output handler, where it would end F# Interactive, so such a folder
is left out there.
…locals open in #r "paket:"

What dotnet left running and keeps its output open stayed running after
#r "paket:" took the folder. Once dotnet exited, only Process.Kill(true) on
Windows still finds the processes that it started, from its handle, and
theirs through the ones that still run: on Linux and macOS it no longer
looks for them, and .NET Framework has no Kill(true). There, the end of the
output is waited for within 5 seconds after dotnet exits in all, after a
failure, a folder or neither, and what keeps it open is then killed.
…out in #r "paket:"

A dotnet that printed its global-packages line and then hangs on exit gave
TimedOut without its folder: the folder read from that line is now kept, and
no other folder is asked for, as after any timeout.
@fpellet fpellet changed the title perf(#r "paket:"): look for dotnet once and run dotnet nuget locals at most once per folder perf(#r "paket:"): look for dotnet once and run dotnet nuget locals once per folder, without waiting for an output left open Nov 22, 2026
@fpellet
fpellet merged commit 0fe2f86 into master Nov 22, 2026
12 checks passed
@fpellet
fpellet deleted the perf/fsi-dotnet-once branch November 22, 2026 09:41
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.

1 participant