-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
vm: implement vm.measureMemory() for per-context memory measurement #31824
Conversation
ba8d46b
to
bc6f5fe
Compare
This patch implements `vm.measureMemory()` with the new `v8::Isolate::MeasureMemory()` API to measure per-context memory usage. This should be experimental, since detailed memory measurement requires further integration with the V8 API that should be available in a future V8 update.
bc6f5fe
to
6c04e3c
Compare
Is there a reason we don't want to expose this on |
@devsnek This is currently different from the API proposed in https://github.com/ulan/performance-measure-memory in that an |
@joyeecheung did you have any interest in the Context.current() approach I mentioned in irc? |
@devsnek That sounds interesting but seems orthogonal to what this PR does? |
@joyeecheung well if we wanted to use that approach instead i assume we wouldn't also have the static method this pr adds, which is why i ask |
@devsnek A measureMemory method could be added to the prototype of the Context class but that when the API does land, yes, but I think it's better to decouple the functionality of measuring the per-context memory from an API that has not landed yet, and this provides the functionality for contextified objects which is something that does exist in the wild (it could also take the new class when the time comes, and avoids the overhead of creating an extra wrapper for the invoking context). |
@bnoordhuis @addaleax @jasnell @lundibundi Thanks for the reviews. I've updated the PR, PTAL.
|
…ement Co-Authored-By: Colin Ihrig <[email protected]>
This patch implements `vm.measureMemory()` with the new `v8::Isolate::MeasureMemory()` API to measure per-context memory usage. This should be experimental, since detailed memory measurement requires further integration with the V8 API that should be available in a future V8 update. PR-URL: #31824 Refs: https://github.com/ulan/performance-measure-memory Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Landed in fb73045, thanks! |
This patch implements `vm.measureMemory()` with the new `v8::Isolate::MeasureMemory()` API to measure per-context memory usage. This should be experimental, since detailed memory measurement requires further integration with the V8 API that should be available in a future V8 update. PR-URL: #31824 Refs: https://github.com/ulan/performance-measure-memory Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
It seems the example code is wrong, the docs suggest the function should be called like this |
Do you mind send a PR for this ? |
I'm currently busy updating the node type definitions to v11 (hence this comment). |
@joyeecheung i did a test, The data is not as expected,:
|
@limerickgds This no longer works after the recent V8 update - the promises returned by 'use strict';
const vm = require('vm');
require('util').inspect.defaultOptions.depth = 100;
function getMeasureMemory() {
return vm.measureMemory({ mode: 'detailed', execution: 'eager' });
}
let globalStore = [];
const operateStore = {
add: () => {
let i = 1000;
while (i--) { globalStore.push('test'.repeat(10000)); }
},
remove: () => {
globalStore = [];
},
};
const script = `
var store = [];
fn = {
add: () => {
let i = 1000;
while(i--){ store.push('test'.repeat(10000)) }
},
remove: () => {
store = [];
}
}
`;
const context = vm.createContext({
fn: () => {},
console,
});
vm.runInContext(script, context);
async function measureMemoryTest() {
let result = {};
result = await getMeasureMemory();
console.log('start: \n', result);
context.fn.add();
result = await getMeasureMemory();
console.log('after add once: \n', result);
context.fn.remove();
result = await getMeasureMemory();
console.log('after remove all: \n', result);
operateStore.add();
result = await getMeasureMemory();
console.log('after add global context: \n', result);
}
measureMemoryTest();
This seems to be about right (according to the ranges, instead of the estimates which are pretty rough since it's measured after marking, and before sweeping) |
This patch implements
vm.measureMemory()
with the newv8::Isolate::MeasureMemory()
API to measure per-context memoryusage. This should be experimental, since detailed memory
measurement requires further integration with the V8 API
that should be available in a future V8 update.
Refs: https://github.com/ulan/performance-measure-memory
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes