Skip to content

Commit 2348fd1

Browse files
authored
fix: update devtools-frontend (#125)
1 parent 6e25c72 commit 2348fd1

File tree

3 files changed

+266
-154
lines changed

3 files changed

+266
-154
lines changed

scripts/devtools.rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default {
4343
__entry__: `
4444
export { HeapSnapshotLoader } from './front_end/entrypoints/heap_snapshot_worker/heap_snapshot_worker.ts'
4545
export { HeapSnapshotModel } from './front_end/models/heap_snapshot_model/heap_snapshot_model.ts'
46+
export { SecondaryInitManager } from './front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts'
4647
`,
4748
// Promise.withResolvers minimal shim
4849
// TODO: remove when we set our minimum Node to v22+

src/metrics/heapsnapshots/heapsnapshots.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import path from 'node:path'
22
import { createReadStream, createWriteStream } from 'node:fs'
33
import { realpath } from 'node:fs/promises'
44
import { tmpdir } from 'node:os'
5-
import { HeapSnapshotLoader } from '../../thirdparty/devtools-frontend/index.js'
5+
import {
6+
HeapSnapshotLoader,
7+
SecondaryInitManager
8+
} from '../../thirdparty/devtools-frontend/index.js'
69
import { randomUUID } from 'node:crypto'
710

811
// via https://github.com/sindresorhus/temp-dir/blob/437937c/index.js#L4
@@ -54,5 +57,19 @@ export async function createHeapSnapshotModel (filename) {
5457
loader.close()
5558
await loader.parsingComplete
5659

57-
return (await loader.buildSnapshot())
60+
// Pattern borrowed from `createJSHeapSnapshotForTesting` in Chromium code.
61+
// https://github.com/ChromeDevTools/devtools-frontend/blob/866e7ab/front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts#L3675-L3682
62+
// Rather than trying to make it work with two workers, we just do it all in one thread.
63+
// For context see this commit splitting the work into two workers:
64+
// https://github.com/ChromeDevTools/devtools-frontend/commit/6a523a7
65+
const channel = new MessageChannel()
66+
try {
67+
// eslint-disable-next-line no-new
68+
new SecondaryInitManager(channel.port2)
69+
return await loader.buildSnapshot(channel.port1)
70+
} finally {
71+
// Without this, the Node process will just hang forever
72+
channel.port1.close()
73+
channel.port2.close()
74+
}
5875
}

0 commit comments

Comments
 (0)