Skip to content

Commit

Permalink
Introduce Caching to the Command Executor (#2110)
Browse files Browse the repository at this point in the history
* Introduce Caching to the Command Executor

Every time we run a command we spawn a new child process, which is expensive.
Commands may differ a lot based on the CWD, shell, and other factors. However, with many extensions relying on us, C# and C# DevKit for example, often make us call 'dotnet_executable_path --info' with the same settings. This is a lot of overhead which can be cached.

We can't cache it for too long because if someone edits the system, the result of dotnet --info may change. But most of the calls to info etc happen at the launch of the window which is also where perf is more vital.

We add a setting to disable the cache or make it extended longer.
This pattern allows caching in the future.

We rely on node-cache which is a reputable library and MIT license.

For everything that we want to be cached, we send the TTL for that command to the executor via options.dotnetInstallToolCacheTtlMs. That is separated into a different commit.

The easiest way to test this is to open our extension log and see that things get cached and that changes depending on the ttl setting.

* Install node-cache

* Fix package lock

* Update Packages

* Update Dependencies Again

* Turn on cacheing for individual commands

* Fix Lint

* Call ABS on the Cache Value to protect from negative input

* Fix whitespace so setting shows up

* Fix bug where cache wouldnt get used

* Cache more stuff!

* Cache more!

* Cache More Stuff

* Fix Lint

* Get the TTL before it's deleted.

* Dont delete from the obj as that breaks Single Respon Principle

* Cache the dotnet --info less as it appears to be too long

* fix path lookup

it could return all runtimes since the env wasnt set thus ignoring the setting

* add save on format settings for the repo

* add cache tests

* Improve ? handling

* Improve ? handling

* Simplify Code

Co-authored-by: Michael Yanni <[email protected]>

* Simplify code.

Co-authored-by: Michael Yanni <[email protected]>

* Fix whitespace

Co-authored-by: Michael Yanni <[email protected]>

* Fix whitespace

Co-authored-by: Michael Yanni <[email protected]>

* Fix code style

---------

Co-authored-by: Michael Yanni <[email protected]>
  • Loading branch information
nagilson and MiYanni authored Feb 11, 2025
1 parent 674f368 commit dfd0283
Show file tree
Hide file tree
Showing 37 changed files with 5,808 additions and 4,613 deletions.
1,603 changes: 989 additions & 614 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions sample/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions sample/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
version "1.17.0"
resolved "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/@azure/core-rest-pipeline/-/core-rest-pipeline-1.17.0.tgz"
integrity sha1-Vdr6EJNVPFSe1tjbymmqUFx7OqM=
"resolved" "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/@azure/core-rest-pipeline/-/core-rest-pipeline-1.17.0.tgz"
dependencies:
"@azure/abort-controller" "^2.0.0"
"@azure/core-auth" "^1.8.0"
Expand Down Expand Up @@ -2140,9 +2139,9 @@ underscore@^1.12.1:
integrity sha1-lw4zljr5p92iKPF+voOZ5fvmOhA=

undici@^6.19.5:
version "6.20.1"
resolved "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/undici/-/undici-6.20.1.tgz"
integrity sha1-+7h7Hitp2WP/LVQQpA/7TJ6BtiE=
version "6.21.1"
resolved "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/undici/-/undici-6.21.1.tgz"
integrity sha1-M2AloUFi5oN+RK17gZs1tsavDgU=

update-browserslist-db@^1.1.0:
version "1.1.1"
Expand Down Expand Up @@ -2196,7 +2195,9 @@ uuid@^8.3.0:
eol "^0.9.1"
get-proxy-settings "^0.1.13"
https-proxy-agent "^7.0.4"
lodash "^4.17.21"
mocha "^9.1.3"
node-cache "^5.1.2"
open "^8.4.0"
proper-lockfile "^4.1.2"
rimraf "3.0.2"
Expand Down Expand Up @@ -2245,7 +2246,6 @@ uuid@^8.3.0:
chai "4.3.4"
chai-as-promised "^7.1.1"
glob "^7.2.0"
is-online "^9.0.1"
mocha "^9.1.3"
open "^8.4.0"
rimraf "3.0.2"
Expand Down
42 changes: 32 additions & 10 deletions vscode-dotnet-runtime-extension/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
// Formatting for every file
"editor.formatOnSave": true,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
"javascript.format.placeOpenBraceOnNewLineForFunctions": true,
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": false,
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"typescript.format.placeOpenBraceOnNewLineForFunctions": true,
"dotnetAcquisitionExtension.installTimeoutValue": 300,
"typescript.inlayHints.enumMemberValues.enabled": true,
"typescript.inlayHints.functionLikeReturnTypes.enabled": true,
"typescript.inlayHints.parameterNames.enabled": "all",
"typescript.referencesCodeLens.enabled": true,
"typescript.referencesCodeLens.showOnAllFunctions": true,
"typescript.implementationsCodeLens.enabled": true,
"typescript.implementationsCodeLens.showOnInterfaceMethods": true,
"typescript.preferences.quoteStyle": "single",
"typescript.preferGoToSourceDefinition": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
Loading

0 comments on commit dfd0283

Please sign in to comment.