Skip to content

Add method to take a save a JS memory heap snapshot#49125

Closed
rubennorte wants to merge 1 commit into
facebook:mainfrom
rubennorte:export-D68953788
Closed

Add method to take a save a JS memory heap snapshot#49125
rubennorte wants to merge 1 commit into
facebook:mainfrom
rubennorte:export-D68953788

Conversation

@rubennorte
Copy link
Copy Markdown
Contributor

Summary:
Changelog: [internal]

This adds support for taking JS memory heap snapshots from Fantom tests via Fantom.saveJSMemoryHeapSnapshot. This can be used in one-off tests to do memory analysis and determine the existence of leaks:

// Warm up

Fantom.saveJSMemoryHeapSnapshot('/path/to/my/1.heapsnapshot');

// Do work

Fantom.saveJSMemoryHeapSnapshot('/path/to/my/2.heapsnapshot');

// Clean up

Fantom.saveJSMemoryHeapSnapshot('/path/to/my/3.heapsnapshot');

Load these snapshots in Chrome and select "Objects allocated between 1 and 2" in the dropdown to see the potentially leaked objects.

In the future we could introduce additional utilities to analyze the snapshots and do the detection automatically, e.g.:

// Warm up

const baseline = Fantom.takeJSMemoryHeapSnapshot();

// Do work

const before = Fantom.takeJSMemoryHeapSnapshot();

// Clean up

const after = Fantom.takeJSMemoryHeapSnapshot();

const leaks = findMemoryLeaks(baseline, before, after);
expect(leaks.sizeKB()).toBeLessThan(THRESHOLD);

Differential Revision: D68953788

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 3, 2025
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D68953788

Summary:

Changelog: [internal]

This adds support for taking JS memory heap snapshots from Fantom tests via `Fantom.saveJSMemoryHeapSnapshot`. This can be used in one-off tests to do memory analysis and determine the existence of leaks:

```
// Warm up

Fantom.saveJSMemoryHeapSnapshot('/path/to/my/1.heapsnapshot');

// Do work

Fantom.saveJSMemoryHeapSnapshot('/path/to/my/2.heapsnapshot');

// Clean up

Fantom.saveJSMemoryHeapSnapshot('/path/to/my/3.heapsnapshot');
```

Load these snapshots in Chrome and select "Objects allocated between 1 and 2" in the dropdown to see the potentially leaked objects.

In the future we could introduce additional utilities to analyze the snapshots and do the detection automatically, e.g.:

```
// Warm up

const baseline = Fantom.takeJSMemoryHeapSnapshot();

// Do work

const before = Fantom.takeJSMemoryHeapSnapshot();

// Clean up

const after = Fantom.takeJSMemoryHeapSnapshot();

const leaks = findMemoryLeaks(baseline, before, after);
expect(leaks.sizeKB()).toBeLessThan(THRESHOLD);
```

Reviewed By: rshest

Differential Revision: D68953788
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D68953788

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Feb 4, 2025
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in d2a6ff0.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @rubennorte in d2a6ff0

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants