refactor: allocate api::App on cpp heap (#48118)
This commit is contained in:
parent
d4b7d9e9cf
commit
dd54e84a58
7 changed files with 133 additions and 26 deletions
45
spec/cpp-heap-spec.ts
Normal file
45
spec/cpp-heap-spec.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { expect } from 'chai';
|
||||
|
||||
import * as path from 'node:path';
|
||||
|
||||
import { startRemoteControlApp } from './lib/spec-helpers';
|
||||
|
||||
describe('cpp heap', () => {
|
||||
describe('app module', () => {
|
||||
it('should not allocate on every require', async () => {
|
||||
const { remotely } = await startRemoteControlApp();
|
||||
const [usedBefore, usedAfter] = await remotely(async () => {
|
||||
const { getCppHeapStatistics } = require('node:v8');
|
||||
const heapStatsBefore = getCppHeapStatistics('brief');
|
||||
{
|
||||
const { app } = require('electron');
|
||||
console.log(app.name);
|
||||
}
|
||||
{
|
||||
const { app } = require('electron');
|
||||
console.log(app.dock);
|
||||
}
|
||||
const heapStatsAfter = getCppHeapStatistics('brief');
|
||||
return [heapStatsBefore.used_size_bytes, heapStatsAfter.used_size_bytes];
|
||||
});
|
||||
expect(usedBefore).to.be.equal(usedAfter);
|
||||
});
|
||||
|
||||
it('should record as node in heap snapshot', async () => {
|
||||
const { remotely } = await startRemoteControlApp(['--expose-internals']);
|
||||
const [nodeCount, hasPersistentParent] = await remotely(async (heap: string) => {
|
||||
const { recordState } = require(heap);
|
||||
const state = recordState();
|
||||
const rootNodes = state.snapshot.filter(
|
||||
(node: any) => node.name === 'Electron / App' && node.type !== 'string');
|
||||
const hasParent = rootNodes.some((node: any) => node.incomingEdges.some(
|
||||
(edge: any) => {
|
||||
return edge.type === 'element' && edge.from.name === 'C++ Persistent roots';
|
||||
}));
|
||||
return [rootNodes.length, hasParent];
|
||||
}, path.join(__dirname, '../../third_party/electron_node/test/common/heap'));
|
||||
expect(nodeCount).to.equal(1);
|
||||
expect(hasPersistentParent).to.be.true();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue