Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page.collectGarbage() #1394

Closed
pragmaproducts opened this issue Nov 15, 2017 · 10 comments

Comments

Projects
None yet
6 participants
@pragmaproducts
Copy link

commented Nov 15, 2017

I would like to collect garbage in the process of tests so that I can do metrics and doing traces between operations.

Chrome dev tools has a clear garbage button on the performance tab.
Can we get access to the operations of that button please in the same way as you can do it manually on the performance tab.

something like page.collectGarbage() would be really appreciated.

@Everettss

This comment has been minimized.

Copy link

commented Nov 15, 2017

Since we are waiting for #31 you can use at this moment Chrome DevTools Protocol - HeapProfiler.collectGarbage:

await page._client.send('HeapProfiler.enable');
await page._client.send('HeapProfiler.collectGarbage');

@aslushnikov aslushnikov added the feature label Nov 21, 2017

@aslushnikov

This comment has been minimized.

Copy link
Contributor

commented Nov 21, 2017

cc @a1ph

@trentmwillis

This comment has been minimized.

Copy link
Contributor

commented Dec 5, 2017

@aslushnikov is this feature still desired? If so, I'd be happy to implement it with some guidance on what exactly the internals should be. Perhaps it is just HeapProfiler.enable > HeapProfiler.collectGarbage > HeapProfiler.disable?

@aslushnikov

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2017

@trentmwillis @Everettss @pragmaproducts The page.collectGarbage() would be quite racy, I'm not convinced this is anyhow useful. Consider the following pptr script:

// This would successfully collect garbage
await page.collectGarbage();
// However, by the time control is returned to pptr,
// the page could've produced a ton more garbage
startCollectingMyMetrics();

If you do memory analysis, queryObjects API is much more robust.

Can you guys share your usecases?

@wrager

This comment has been minimized.

Copy link

commented Dec 26, 2017

@aslushnikov In my case, I would like to make sure that the scheduled garbage collection can not affect my performance metrics:

// It would be nice to force the GC here:
await page.collectGarbage();
const startTime = performance.now();
// Some actions that I measure
const endTime = performance.now() - startTime;
@trentmwillis

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2018

@aslushnikov while that is true, I believe it would be helpful for verifying that certain objects are not being retained (a.k.a., leaking). For example:

// Page has performed some action

// Force a GC to ensure garbage from previous actions has been collected
await page.collectGarbage();

// Verify object has not been accidentally retained after the action
const objs = await page.queryObjects(objectsThatShouldGetCleanedUp);
expect(objs.length).to.equal(0);

If there is a better way to approach the above, I'm totally good with that as well. But this is the use case I'm interested in.

@aslushnikov

This comment has been minimized.

Copy link
Contributor

commented Jan 12, 2018

@trentmwillis I believe page.queryObjects already calls gc internally, so it should return only retained objects.

cc @ak239 who can confirm/deny this claim.

@ak239

This comment has been minimized.

Copy link
Contributor

commented Jan 12, 2018

Yes, queryObjects internally calls gc.

@trentmwillis

This comment has been minimized.

Copy link
Contributor

commented Jan 12, 2018

Awesome, that works for me then! Can't think of another use for this API as of now.

@aslushnikov

This comment has been minimized.

Copy link
Contributor

commented Apr 7, 2018

@aslushnikov In my case, I would like to make sure that the scheduled garbage collection can not affect my performance metrics:

Unfortunately, even after calling gc manually, there's no guarantee it won't be triggered during the measured code snippet.

We can re-consider this later if there are more usecases; closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.