Skip to content
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

Add spec for IFrameMemoryUsage.md #3234

Merged
merged 1 commit into from
Mar 15, 2023

Conversation

JosephJin0815
Copy link
Contributor

This is a review for the new IFrame memory usage API.

@JosephJin0815 JosephJin0815 added the API Proposal Review WebView2 API Proposal for review. label Feb 22, 2023
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2_18")]
{
// ICoreWebView2_18 members
UInt32 ProcessId { get; };
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably name this RendererProcessId (and rename all the rest too). There's different kinds of processes and we should make it clear what this is.

```c# (but really MIDL3)
namespace Microsoft.Web.WebView2.Core
{
runtimeclass CoreWebView2FrameCreatedEventArgs
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same runtimeclass that already exists correct? No modifications? If so and you want to include it please add a comment noting that this is an existing unchanged class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. Will remove this from spec.

}
}

// Skipping class CoreWebView2FrameInfoCollection
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this comment. The frame info is not relevant to this doc

```
C#
```c#
void WebView_HandleIFrames(object sender, CoreWebView2FrameCreatedEventArgs args)
Copy link
Contributor

Choose a reason for hiding this comment

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

The C# and C++ sample code should be the same. Currently the C++ code creates a message whereas the C# code creates a frames list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will refine that later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refined. I added some comments for both when renderer process id changed/obtained.

unsigned int processId;
CHECK_FAILURE(webviewFrame5->get_ProcessId(&processId));
message +=
L",\"render process id\": " + std::to_wstring((int)processId);
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't do anything with this message we create. Is there a real scenario we can demonstrate with the FrameCreated event? What did we do for the sample code in the CoreWebView2.FrameCreated spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Win Sample App -> Window Event Monitor, we print out this message. I will add that to the spec.

Copy link
Contributor

Choose a reason for hiding this comment

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

But what is the real world scenario? I guess we're adding it so apps can monitor performance and such via telemetry so this is perhaps fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apps can get memory usage based on process id.

unsigned int processId;
CHECK_FAILURE(webviewFrame5->get_ProcessId(&processId));
message +=
L",\"render process id\": " + std::to_wstring((int)processId);
Copy link
Contributor

Choose a reason for hiding this comment

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

But what is the real world scenario? I guess we're adding it so apps can monitor performance and such via telemetry so this is perhaps fine.

// MSOWNERS: [email protected]
HRESULT remove_FrameCreated([in] EventRegistrationToken token);

/// Get the render process id of the iframe.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to explain just a bit about the renderer process for a frame: The render process ID can change when navigating to a new document and you can use the RenderProcessIdChanged event to know when it changes. Child frames may have different renderer processes. See the process model documentation for more information.


/// Get the render process id of the iframe.
// MSOWNERS: [email protected]
[propget] HRESULT RenderProcessId([out, retval] UINT32* value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Chromium code and documentation (https://www.chromium.org/developers/design-documents/multi-process-architecture/) calls this 'renderer process' not 'render process'. Do we already have reference to 'render process' in our APIs? If so we can match that existing term. Otherwise would be good to name 'renderer process'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No existing APIs use render process as naming. Agree!

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like both show up already. Since we're already inconsistent we can go with the more accurate one renderer. COREWEBVIEW2_PROCESS_FAILED_KIND uses 'render' and COREWEBVIEW2_PROCESS_KIND uses 'renderer'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed.

// MSOWNERS: [email protected]
[propget] HRESULT RenderProcessId([out, retval] UINT32* value);

/// Subscribe to render process Id changed event.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to add some additional context, "The render process ID can change when X happens"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Contributor

@david-risney david-risney left a comment

Choose a reason for hiding this comment

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

Looks good. Just some small wording updates. Please fix wording, complete PR, open new PR to main, and let me know link to new PR and I will schedule API review meeting.

# Background
The WebView2 team has been asked to provide support for monitoring iframe
memory usage. Developer needs to know how much memory each iframe consumes.
To do that, they need to get renderer process id for each iframe". However,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To do that, they need to get renderer process id for each iframe". However,
To do that, they need to get the renderer process ID for each iframe. However,


# Background
The WebView2 team has been asked to provide support for monitoring iframe
memory usage. Developer needs to know how much memory each iframe consumes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
memory usage. Developer needs to know how much memory each iframe consumes.
memory usage. The end developer needs to know how much memory each iframe consumes.

The WebView2 team has been asked to provide support for monitoring iframe
memory usage. Developer needs to know how much memory each iframe consumes.
To do that, they need to get renderer process id for each iframe". However,
WV2 only tracks the render frame host for top-level iframes. This limits the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
WV2 only tracks the render frame host for top-level iframes. This limits the
WebView2 only tracks the render frame host for top-level iframes. This limits the

memory usage. Developer needs to know how much memory each iframe consumes.
To do that, they need to get renderer process id for each iframe". However,
WV2 only tracks the render frame host for top-level iframes. This limits the
[ICoreWebView2Frame2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2frame?view=webview2-1.0.1518.46) apis for first-level iframes only. For instance, we can handle iframe created event for first-level iframe,
Copy link
Contributor

Choose a reason for hiding this comment

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

Break long line and wording updates

Suggested change
[ICoreWebView2Frame2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2frame?view=webview2-1.0.1518.46) apis for first-level iframes only. For instance, we can handle iframe created event for first-level iframe,
[ICoreWebView2Frame2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2frame?view=webview2-1.0.1518.46) APIs
for first-level iframes only. For instance, we raise the FrameCreated event for first-level iframes,

To do that, they need to get renderer process id for each iframe". However,
WV2 only tracks the render frame host for top-level iframes. This limits the
[ICoreWebView2Frame2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2frame?view=webview2-1.0.1518.46) apis for first-level iframes only. For instance, we can handle iframe created event for first-level iframe,
but not for nested iframes with depth greater than 1. Also, WV2 lacks an API to
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
but not for nested iframes with depth greater than 1. Also, WV2 lacks an API to
but not for nested iframes with depth greater than 1. Also, WebView2 lacks an API to

WV2 only tracks the render frame host for top-level iframes. This limits the
[ICoreWebView2Frame2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2frame?view=webview2-1.0.1518.46) apis for first-level iframes only. For instance, we can handle iframe created event for first-level iframe,
but not for nested iframes with depth greater than 1. Also, WV2 lacks an API to
get the renderer process id for its iframe.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
get the renderer process id for its iframe.
get the renderer process ID for iframes.

the renderer process id is changed for `CoreWebView2` or `CoreWebView2Frame`.

Additionally, we propose to add the `FrameCreated` event to `CoreWebView2Frame`.
This event fires when a new frame is created.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This event fires when a new frame is created.
This event is raised when a new frame is created.

Add iframe memory usage API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment