From c8355614df7f34c8cc18a3ddecddef5cb9297422 Mon Sep 17 00:00:00 2001 From: John Murray Date: Fri, 20 Sep 2024 14:42:31 +0100 Subject: [PATCH] Solve 1.93 performance issue (#1432) * Bump node-fetch-cjs to investigate 1.93 performance issue * Reuse Agent across requests * Don't enable keepAlive, in case this is causing #1428 * Add comments now the workaround has been validated --- package-lock.json | 15 ++++++++------- package.json | 2 +- src/api/index.ts | 20 ++++++++++++++------ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 63c3fd4a..b4d3df97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "istextorbinary": "^6.0.0", "minimatch": "^9.0.3", "node-cmd": "^5.0.0", - "node-fetch-cjs": "3.1.1", + "node-fetch-cjs": "^3.3.2", "vscode-cache": "^0.3.0", "vscode-extension-telemetry": "^0.1.6", "ws": "^8.14.2" @@ -3746,9 +3746,10 @@ } }, "node_modules/node-fetch-cjs": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/node-fetch-cjs/-/node-fetch-cjs-3.1.1.tgz", - "integrity": "sha512-YOMqQ94r/1o95JS3yFye1czAVY6i3xreA6tsNnloLCKJKbfFMxgkhsLH0yYI0vWXBZmEQ80l66ue6UqFAgVv2g==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch-cjs/-/node-fetch-cjs-3.3.2.tgz", + "integrity": "sha512-JvvyTiDcLnHvPmbxj6uxj4LaamCfZLlzlRNBZp+H82ECMLz4OQjI9Jc6YjjjycipeMk1Aq4xo90ejEUMKJeTjw==", + "license": "MIT", "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, @@ -8134,9 +8135,9 @@ "integrity": "sha512-4sQTJmsS5uZKAPz/Df9fnIbmvOySfGdW+UreH4X5NcAOOpKjaE+K5wf4ehNBbZVPo0vQ36RkRnhhsXXJAT+Syw==" }, "node-fetch-cjs": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/node-fetch-cjs/-/node-fetch-cjs-3.1.1.tgz", - "integrity": "sha512-YOMqQ94r/1o95JS3yFye1czAVY6i3xreA6tsNnloLCKJKbfFMxgkhsLH0yYI0vWXBZmEQ80l66ue6UqFAgVv2g==" + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch-cjs/-/node-fetch-cjs-3.3.2.tgz", + "integrity": "sha512-JvvyTiDcLnHvPmbxj6uxj4LaamCfZLlzlRNBZp+H82ECMLz4OQjI9Jc6YjjjycipeMk1Aq4xo90ejEUMKJeTjw==" }, "node-releases": { "version": "2.0.18", diff --git a/package.json b/package.json index 3188abb2..b37cebbd 100644 --- a/package.json +++ b/package.json @@ -1842,7 +1842,7 @@ "istextorbinary": "^6.0.0", "minimatch": "^9.0.3", "node-cmd": "^5.0.0", - "node-fetch-cjs": "3.1.1", + "node-fetch-cjs": "^3.3.2", "vscode-cache": "^0.3.0", "@vscode/debugadapter": "^1.61.0", "@vscode/debugprotocol": "^1.61.0", diff --git a/src/api/index.ts b/src/api/index.ts index 6879b28f..cffdcc79 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -43,6 +43,7 @@ export interface ConnectionSettings { export class AtelierAPI { private _config: ConnectionSettings; + private _agent?: httpModule.Agent | httpsModule.Agent; private namespace: string; public configName: string; @@ -303,11 +304,18 @@ export class AtelierAPI { const proto = this._config.https ? "https" : "http"; const http = this._config.https ? httpsModule : httpModule; - const agent = new http.Agent({ - keepAlive: true, - maxSockets: 10, - rejectUnauthorized: https && vscode.workspace.getConfiguration("http").get("proxyStrictSSL"), - }); + if (!this._agent) { + this._agent = new http.Agent({ + /* VS Code 1.93 adopted a version of vscode-proxy-agent that fixed a failure to pass-through the keepAlive option (see https://github.com/microsoft/vscode/issues/173861 and https://github.com/microsoft/vscode-proxy-agent/commit/4eddc930d4fbc6b88ca5557ea7af07d623d390d6) + * This caused poor performance on some operations by our extension (see https://github.com/intersystems-community/vscode-objectscript/issues/1428) + * Short term solution adopted by PR https://github.com/intersystems-community/vscode-objectscript/pull/1432 is not to enable keepAlive + * We should revisit this in the future - TODO + */ + //keepAlive: true, + //maxSockets: 10, + rejectUnauthorized: https && vscode.workspace.getConfiguration("http").get("proxyStrictSSL"), + }); + } let pathPrefix = this._config.pathPrefix || ""; if (pathPrefix.length && !pathPrefix.startsWith("/")) { @@ -340,7 +348,7 @@ export class AtelierAPI { const cookie = await auth; const response = await fetch(`${proto}://${host}:${port}${path}`, { method, - agent, + agent: this._agent, body: body ? (typeof body !== "string" ? JSON.stringify(body) : body) : null, headers: { ...headers,