-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
feat(core): Deno.core.heapStats() #9659
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs tests but other than that the technical side of the PR looks good to me, thanks.
Another maintainer should weigh in on the API.
} | ||
|
||
// HeapStats stores values from a isolate.get_heap_statistics() call | ||
struct HeapStats { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you're wrapping v8::HeapStatistics
because that makes it easier to serialize in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, with serde_v8
(and the new op-ABI) all the set_prop()
calls would become a one-liner to_v8()
and by keeping it in a struct we can have serde handle the camelCase-ification (if desired).
There are other core binding funcs that will be simplified with serde_v8
, e.g: get_proxy_details
and get_promise_details
conceptually return tuples, which serde_v8
can serialize to JS arrays (removing a fair amount of boilerplate in each function)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could probably add some simple alloc-dealloc tests (of large arrays) to ensure they are correctly reflected in the metrics.
Anything else that warrants testing in your opinion ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AaronO such test would be sufficient
Nit; we should probably camelCase these properties? |
Yes |
@caspervonb @bartlomieju Here's my reasoning:
Maybe something like this: {
heapTotal,
heapExecutable,
physical,
available,
globalHandlesTotal,
globalHandlesUsed,
heapUsed,
heapLimit,
malloced,
external,
mallocedPeak,
nativeContexts,
detachedContexts,
} (Not alphabetically sorted/grouped with new names) vs {
total_heap_size,
total_heap_size_executable,
total_physical_size,
total_available_size,
total_global_handles_size,
used_global_handles_size,
used_heap_size,
heap_size_limit,
malloced_memory,
external_memory,
peak_malloced_memory,
number_of_native_contexts,
number_of_detached_contexts,
} |
Looks good to me, but this should wait for 1.9.0, I think. Unfortunately that's 6 weeks out as we just released 1.8.0 yesterday. It could be argued that Deno.core is not part of the public API. It's not listed in "deno types" so maybe this could go out in a patch release. Interested in other's opinions... |
I think we should just land for 1.9. Merge window opens on 17th right? It will be in main for 4 weeks then. As this will mainly be used for benchmarking, it only needs to be in |
I agree with that, we've already did this several times, I see no point in holding it off. That said I don't like that the fields are using |
@bartlomieju I'll switch this to camelCase and add tests later today, so we can merge this then (I was hoping to camelCase through I'll do a separate PR on adding this "baseline isolate heap" to the benchmarks since there's some meta-discussion to be had on where to put it (doesn't perfectly fit with the other "max memory" benches and also differs from them by an order of magnitude) |
Since it uses a v8 flag (--expose-gc) it doesn't fit as core test
@bartlomieju The windows test release failed for an unrelated (DNS error), I don't think I can retry it, could you ? Otherwise linting & tests pass. |
@AaronO done, I think this is good to land as is |
@bartlomieju great, thanks ! |
This implements
Deno.core.heapStats()
so we can programatically measure isolate heap-usage (for benchmarks, etc...)Sample output
Heap usage
.used_heap_size
is the most relevant individual metricWith
1.8.0
it has grown from~2MB to ~2.25MB
(most likely due to the added JS for WebGPU,~190kb
of JS src)I had originally reported2MB => 3MB
since I was sampling on a debug releaseThis is measured by:
Notes
Deno.metrics
at some point (to have a single func to get general metrics).1.8.0
increase)