feat: Add a JS binding for MemoryPressureMonitor#118
feat: Add a JS binding for MemoryPressureMonitor#118caneraltinbasak merged 4 commits into28-x-y-bsfrom
Conversation
6cb9adb to
32c4148
Compare
| ### `memoryPressureMonitor.notifyMemoryPressure(level)` | ||
|
|
||
| * `level` string - The pressure level to broadcast. Must be `moderate` or | ||
| `critical`. |
There was a problem hiding this comment.
I was wondering why notifyMemoryPressure doesn't send none as an option (i.e. if we notify the level is moderate then after the memory usage has been reduced and the pressure level goes back down to normal)?
There was a problem hiding this comment.
Memory pressure handlers generally don't hold state, they apply an action. But it is a valid point, I'll address that.
32c4148 to
7c948d5
Compare
7c948d5 to
8b497fc
Compare
| * process. Chromium's internal caches, blink, and V8 will react by | ||
| * releasing memory. Respects the notification-suppressed flag. | ||
| * | ||
| * @param level - 'moderate' or 'critical' |
There was a problem hiding this comment.
This should now also include 'none'
There was a problem hiding this comment.
Turns out "none" is not a valid state for MemoryPressureMonitor, there is a DCHECK which triggers if NONE is notified. Tests failed due to that. I'll remove all the changes which I've added for triggering "kNone". As I stated before MemoryPressureListeners do action, they don't hold state.
// static
void MemoryPressureListener::NotifyMemoryPressure(
MemoryPressureLevel memory_pressure_level) {
DCHECK_NE(memory_pressure_level, MEMORY_PRESSURE_LEVEL_NONE);
TRACE_EVENT_INSTANT(
trace_event::MemoryDumpManager::kTraceCategory,
"MemoryPressureListener::NotifyMemoryPressure",
[&](perfetto::EventContext ctx) {
auto* event = ctx.event<perfetto::protos::pbzero::ChromeTrackEvent>();
auto* data = event->set_chrome_memory_pressure_notification();
data->set_level(
trace_event::MemoryPressureLevelToTraceEnum(memory_pressure_level));
});
if (AreNotificationsSuppressed())
return;
DoNotifyMemoryPressure(memory_pressure_level);
}
| * | ||
| * @param level - 'moderate' or 'critical' | ||
| */ | ||
| notifyMemoryPressure (level: string): void { |
There was a problem hiding this comment.
Should have the type here?
notifyMemoryPressure (level: 'none' | 'moderate' | 'critical' )
| * Returns the current memory pressure level reported by the OS. | ||
| * @returns {'none' | 'moderate' | 'critical'} | ||
| */ | ||
| getCurrentPressureLevel (): string { |
There was a problem hiding this comment.
Should have the type here?
getCurrentPressureLevel (): 'none' | 'moderate' | 'critical' {
typings/internal-ambient.d.ts
Outdated
| createMemoryPressureMonitor(): MemoryPressureMonitorBinding; | ||
| getCurrentPressureLevel(): string; | ||
| notifyMemoryPressure(level: string): void; | ||
| emit: (event: string, ...args: any[]) => boolean; |
There was a problem hiding this comment.
Should have typing here instead of string for getCurrentPressureLevel and notifyMemoryPressure?
8b497fc to
2ef568c
Compare
2ef568c to
da0390a
Compare
Add memoryPressureMonitor singleton for main process that wraps Chromiums memory pressure system. Enables listening for OS memory pressure events and programmatically triggering pressure notifications to force cache drops and GC. Changes: - New C++ API: shell/browser/api/electron_api_memory_pressure_monitor.* - New TypeScript wrapper: lib/browser/api/memory-pressure-monitor.ts - Methods: getCurrentPressureLevel(), notifyMemoryPressure(level) - Event: memory-pressure emitted on OS pressure changes - Tests: spec/api-memory-pressure-monitor-spec.ts - Docs: docs/api/memory-pressure-monitor.md - Registration: module-list.ts, node_bindings.cc, filenames.gni, typings
…S-20753, OS-20757 Remove IS_ANDROID guards from Chromium's cross-process memory pressure IPC to enable notifyMemoryPressure() to reach all renderer processes on all platforms via content::mojom::ChildProcess::OnMemoryPressure. Iterate RenderProcessHost instances in the browser process and forward the pressure level to each live renderer, matching the pattern used by UserLevelMemoryPressureSignalGenerator on Android.
We will use the new electron.memoryPressureMonitor to trigger memory pressure events. Electron's memoryPressureMonitor propagates events to render processes too. Remove our previous attempt where we relied on Chromium's own LinuxMemoryPressureMonitor and launching the monitor on both main and renderer processes.
ce720f2 to
107aa16
Compare
107aa16 to
08ad14d
Compare
This pull request has 3 parts: