Skip to content

Commit

Permalink
Solve 1.93 performance issue (#1432)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gjsjohnmurray authored Sep 20, 2024
1 parent a53daf7 commit c835561
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
15 changes: 8 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 14 additions & 6 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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("/")) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c835561

Please sign in to comment.