Skip to content

Commit 55e5d0d

Browse files
authored
Merge pull request #1674 from robbiespeed/modify-gc
Use last-resort gc, fixes #1667
2 parents e361c5c + cd885d6 commit 55e5d0d

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

webdriver-ts/src/forkedBenchmarkRunnerPlaywright.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,8 @@ function convertError(error: any): string {
6060
}
6161
}
6262

63-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
64-
async function forceGC(page: Page, client?: CDPSession) {
65-
for (let i = 0; i < 7; i++) {
66-
// await client.send('HeapProfiler.collectGarbage');
67-
await page.evaluate("window.gc()");
68-
}
63+
async function forceGC(page: Page) {
64+
await page.evaluate("window.gc({type:'major',execution:'sync',flavor:'last-resort'})");
6965
}
7066

7167
async function runCPUBenchmark(
@@ -128,7 +124,7 @@ async function runCPUBenchmark(
128124
config,
129125
fileNameTrace(framework, benchmark.benchmarkInfo, i, benchmarkOptions)
130126
);
131-
127+
132128
let res = { total: result.duration, script: resultScript, paint: resultPaint };
133129
results.push(res);
134130
console.log(`duration for ${framework.name} and ${benchmark.benchmarkInfo.id}: ${JSON.stringify(res)}`);
@@ -195,7 +191,7 @@ async function runMemBenchmark(
195191

196192
console.log("runBenchmark");
197193
await runBenchmark(browser, page, benchmark, framework);
198-
await forceGC(page, client);
194+
await forceGC(page);
199195
await wait(40);
200196
// let result = (await client.send('Performance.getMetrics')).metrics.filter((m) => m.name==='JSHeapUsedSize')[0].value / 1024 / 1024;
201197

webdriver-ts/src/forkedBenchmarkRunnerPuppeteer.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ function convertError(error: any): string {
4949
}
5050
}
5151

52-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
53-
async function forceGC(page: Page, client: CDPSession) {
54-
for (let i = 0; i < 7; i++) {
55-
await client.send("HeapProfiler.collectGarbage");
56-
await page.evaluate("window.gc()");
57-
}
52+
async function forceGC(page: Page) {
53+
await page.evaluate("window.gc({type:'major',execution:'sync',flavor:'last-resort'})");
5854
}
5955

6056
async function runCPUBenchmark(
@@ -111,7 +107,6 @@ async function runCPUBenchmark(
111107
"devtools.timeline",
112108
"disabled-by-default-devtools.timeline",
113109
];
114-
const client = await page.createCDPSession();
115110

116111
// let categories = [
117112
// "-*", // exclude default
@@ -143,7 +138,7 @@ async function runCPUBenchmark(
143138
await wait(50);
144139
await puppeteerWait();
145140

146-
await forceGC(page, client);
141+
await forceGC(page);
147142
await puppeteerWait();
148143

149144
console.log("runBenchmark");
@@ -256,7 +251,7 @@ async function runMemBenchmark(
256251

257252
console.log("runBenchmark");
258253
await runBenchmark(page, benchmark, framework);
259-
await forceGC(page, client);
254+
await forceGC(page);
260255
await wait(40);
261256
let result = ((await page.evaluate("performance.measureUserAgentSpecificMemory()")) as any).bytes / 1024 / 1024;
262257
console.log("afterBenchmark");

0 commit comments

Comments
 (0)