Commit a37a59f
authored
perf: Unload iframe before removing (#3796)
To drastically reduce the amount of memory leaked if the iframe cannot
be garbage collected properly, this PR modifies `terminateJob` to
navigate the iframe away from the Snaps execution environment before
removing it, effectively unloading it.
Before:
```
Explicit Allocations
15.36 MB (100.0%) -- explicit
└──15.36 MB (100.0%) -- window-objects/top(none)/detached
├──15.26 MB (99.40%) -- window(http://localhost:6363/)
│ ├───7.67 MB (49.97%) ++ js-realm(moz-nullprincipal:{45eed705-e0da-4e2b-b0bf-e7ac336c93f4}?http://localhost:6363, http://localhost:6363/)
│ ├───5.76 MB (37.49%) ++ js-realm(moz-nullprincipal:{8cb3b86e-774f-4a1a-bf6a-eeac2636fe9f}?http://localhost:6363, http://localhost:6363/)
│ ├───1.83 MB (11.94%) ++ dom
│ └───0.00 MB (00.00%) ++ (2 tiny)
└───0.09 MB (00.60%) ++ window(chrome://devtools/content/shared/webextension-fallback.html#webextension-flask@metamask.io)
```
After:
```
Explicit Allocations
0.14 MB (100.0%) -- explicit
└──0.14 MB (100.0%) -- window-objects/top(none)/detached/window(about:blank)
├──0.06 MB (46.17%) ++ js-realm(moz-nullprincipal:{0114dc8e-3f5e-4a2c-8008-c4219c84dcc0}?moz-extension://1465affa-73bf-4b77-9103-8afb21b2fa9d, about:blank)
├──0.06 MB (46.17%) ++ js-realm(moz-nullprincipal:{7e2fd14e-3040-493d-862a-9c207eae5213}?moz-extension://1465affa-73bf-4b77-9103-8afb21b2fa9d, about:blank)
├──0.01 MB (07.16%) ++ dom
└──0.00 MB (00.50%) ++ (2 tiny)
```
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Improves termination flow and reduces iframe memory retention by
making job termination asynchronous and explicitly unloading iframes
before removal.
>
> - Changes `AbstractExecutionService.terminateJob` to return a
`Promise<void>` and awaits it in `terminateSnap` and when init times out
in `#initStreams`
> - In `IframeExecutionService`, `terminateJob` now navigates the iframe
to `about:blank` (with a short `withTimeout`-guarded wait for `load`)
before removing it
> - Updates `NodeProcessExecutionService` and `WebViewExecutionService`
`terminateJob` implementations to async (no functional change beyond
signature)
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
c5ec278. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 2b60768 commit a37a59f
4 files changed
Lines changed: 34 additions & 7 deletions
File tree
- packages/snaps-controllers/src/services
- iframe
- node-js
- webview
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
| |||
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
200 | | - | |
| 202 | + | |
201 | 203 | | |
202 | 204 | | |
203 | 205 | | |
| |||
258 | 260 | | |
259 | 261 | | |
260 | 262 | | |
261 | | - | |
| 263 | + | |
262 | 264 | | |
263 | 265 | | |
264 | 266 | | |
| |||
Lines changed: 23 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
34 | 55 | | |
35 | 56 | | |
36 | 57 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
0 commit comments