Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/typescript/src/api/syncChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ export class SyncRpcChannel {
);
}
if (this.collectTiming) {
// A callback may have issued a nested request while waiting for this response.
this.lastBytesSent = typeof payload === "string"
Comment on lines +330 to +331

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And payload itself is the source of truth for the current request?

? Buffer.byteLength(payload, "utf-8")
: payload.length;
this.lastBytesReceived = this._msgPayload.length;
}
return this._msgPayload;
Expand Down
40 changes: 40 additions & 0 deletions packages/typescript/test/sync/timing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { API } from "@typescript/typescript/sync";
import assert from "node:assert";
import {
describe,
test,
} from "node:test";
import { fileURLToPath } from "node:url";
import { createVirtualFileSystem } from "../testUtils.ts";

describe("sync IPC timing", () => {
test("records the outer request size after a nested request", () => {
const fs = createVirtualFileSystem({ "/tsconfig.json": "{}", "/a.ts": "" });
const nestedArgument = "x".repeat(10_000);
let nested = false;
using api = new API({
cwd: fileURLToPath(new URL("../../../../", import.meta.url).toString()),
collectTiming: true,
fs: {
...fs,
readFile: path => {
if (!nested) {
nested = true;
api.parseCommandLine([nestedArgument]);
}
return fs.readFile!(path);
},
},
});
api.createSnapshot({ openProjects: ["/tsconfig.json"] });

assert.ok(nested);
const { recentRequests } = api.getTimingInfo();
const nestedIndex = recentRequests.findIndex(request => request.method === "parseCommandLine");
assert.ok(nestedIndex >= 0);
assert.ok(recentRequests[nestedIndex].bytesSent > nestedArgument.length);
const outer = recentRequests[nestedIndex + 1];
assert.equal(outer.method, "createSnapshot");
assert.ok(outer.bytesSent < nestedArgument.length, `${outer.method} recorded ${outer.bytesSent} bytes sent`);
});
});
Loading