Bug 1944040 - Minimize memory in getTotalMemoryUsage. r=tarek,xpcom-reviewers,mccr8

Bug 1931851 introduced an ML specific memory reporting. The intent was to "Use the memory reporter to get a snapshot of the memory used by the inference process right after the inference is over."

Now memory reporting is a bit tricky. Our custom allocator has several ways to keep spare memory that gets occasionally freed when hitting certain thresholds. The reporting introduced by bug 1931851 just loooks at the lump sum of heap allocated memory, which includes all this overhead.

If we want to continue to look at this overall metric, we need to follow the same pattern as AWSY testing does, that is to explicitly minimize the aforesaid overhead before taking the snapshot. We already have the logic in place for this and must just make it accessible from JS.

Note that this may introduce quite some delay between the moment the inference ends and the moment the snapshot is actually taken. It is unclear if this still matches the original intent or if the engine slowly winds down, too, but it is probably the only thing we can do here to get a sufficiently stable measurement that makes regressions worth looking at them.

Differential Revision: https://phabricator.services.mozilla.com/D235835
This commit is contained in:
Jens Stutte
2025-01-29 12:02:30 +00:00
parent 9c4a2d9988
commit b7ba5b175c
2 changed files with 10 additions and 2 deletions

View File

@@ -430,7 +430,15 @@ async function getTotalMemoryUsage() {
};
await new Promise(r =>
mgr.getReports(handleReport, null, r, null, /* anonymized = */ false)
mgr.getReportsExtended(
handleReport,
null,
r,
null,
/* anonymized = */ false,
/* minimizeMemoryUsage = */ true,
null
)
);
return Math.round(total / 1024 / 1024);

View File

@@ -288,7 +288,7 @@ interface nsIMemoryReporterManager : nsISupports
* then write a DMD report to a file in the usual temporary directory (see
* |dumpMemoryInfoToTempDir| in |nsIMemoryInfoDumper|.)
*/
[noscript] void
void
getReportsExtended(in nsIHandleReportCallback handleReport,
in nsISupports handleReportData,
in nsIFinishReportingCallback finishReporting,