feat: improve the value of memory in the return data of `getSystemMemoryInfo()` by cucbin · Pull Request #47628 · electron/electron · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

feat: improve the value of memory in the return data of getSystemMemoryInfo() #47628

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cucbin
Copy link
Contributor

@cucbin cucbin commented Jul 1, 2025

Description of Change

On macOS, the free value in the memory data obtained from process.getSystemMemoryInfo() differs significantly from the value displayed in Activity Monitor.

The reason is that the free value is calculated from free_count in vm_statistics64_data_t.

The relevant code is located in: https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_metrics_apple.mm;drc=bcbe20a25707502c2ba340cfd4dbe8cd015fa864;l=255

To handle this issue, I propose two approaches:

  • Calculate and return the adjusted value directly in electron_bindings.cc while maintaining the original data format.

  • Add two new fields: cached and purgeable, to provide more granular memory usage details.

Checklist

Release Notes

Notes: Optimize the value of memory.free in the return data of getSystemMemoryInfo()

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jul 1, 2025
Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to expose new numbers, not change existing ones as people will have existing metrics that we'd be breaking.

Also cc @felixrieseberg because I know you've stared at how memory metrics work a lot in the past, any thoughts here

@cucbin cucbin changed the title fix: Optimize the value of memory.free in the return data of getSystemMemoryInfo() fix: Optimize the value of memory in the return data of getSystemMemoryInfo() Jul 2, 2025
@cucbin cucbin changed the title fix: Optimize the value of memory in the return data of getSystemMemoryInfo() fix: Improve the value of memory in the return data of getSystemMemoryInfo() Jul 2, 2025
@cucbin
Copy link
Contributor Author

cucbin commented Jul 2, 2025

@MarshallOfSound I agree with you. I have changed the code.
Thanks.

Copy link
Member

@nikwen nikwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Could you please also adjust the docs?

### `process.getSystemMemoryInfo()`

Could you please also update the PR title and release notes to reflect your most recent change?

@nikwen nikwen changed the title fix: Improve the value of memory in the return data of getSystemMemoryInfo() fix: improve the value of memory in the return data of getSystemMemoryInfo() Jul 2, 2025
@cucbin
Copy link
Contributor Author

cucbin commented Jul 3, 2025

@nikwen
Thanks. Sure, I will complete the relevant API docs. Currently, I'm waiting to see the opinions of other members to determine whether additional data fields are needed or if these two fields are sufficient.

@nikwen nikwen changed the title fix: improve the value of memory in the return data of getSystemMemoryInfo() feat: improve the value of memory in the return data of getSystemMemoryInfo() Jul 3, 2025
@@ -183,8 +183,11 @@ v8::Local<v8::Value> ElectronBindings::GetSystemMemoryInfo(
#endif
dict.Set("free", free);

#if BUILDFLAG(IS_MAC)
dict.Set("cached", mem_info.file_backed);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be named fileBacked instead? I see another property named cached and want to make sure this won't conflict in the future.
https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_metrics.h;l=365;drc=17b4c42cfb3512836655464b0d41d319e819c0b6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this field name might be better, I have considered using this name before.
Originally I wanted to make the name of this field consistent with what is displayed in the Activity Monitor.

Copy link
Member

@itsananderson itsananderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple suggestions for tweaking the docs wording

cucbin and others added 2 commits July 4, 2025 09:04
Co-authored-by: Will Anderson <will@itsananderson.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.