script: Add a ServoInternals.garbageCollectAllContexts()#42798
Conversation
|
Could you instead make it so that |
|
The TestUtil api is gated by Also, and correct me if I'm wrong as I only skimmed the code, |
I see. In that case let's rename this to |
| ScriptThreadMessage::ForceGC => { | ||
| unsafe { | ||
| JS_GC(*GlobalScope::get_cx(), GCReason::API); | ||
| } | ||
| // Notify the constellation that this script thread's GC is complete. | ||
| // Use dummy values for webview_id and pipeline_id since the values | ||
| // don't matter in that case. | ||
| let _ = self.senders.pipeline_to_constellation_sender.send(( | ||
| base::id::TEST_WEBVIEW_ID, | ||
| base::id::PipelineId::new(), | ||
| ScriptToConstellationMessage::ForceGCCompleted, | ||
| )); | ||
| }, |
There was a problem hiding this comment.
Is it possible that the ScriptThread shuts down before the message is received and the Constellation never receives a reply and goes into a state where a GC cannot be forced again?
There was a problem hiding this comment.
Yes - I added a mitigation that by rejecting the promise if we detect that a ScriptThread did shut down during the browser wide GC.
A more proper fix would require to track which script thread did answer and remove dying ones. I'm not sure that the complexity is warranted here.
There was a problem hiding this comment.
As this can fail, I think it's better to make this API even simpler. Instead of making this API return a promise, let's just let it happen asynchronously. The user can then just wait for the new memory results to settle. It's not quite as nice, but it's also a bit less of a lie. Opening a new tab or closing one could cause really weird behavior otherwise.
c52a465 to
d08840e
Compare
mrobinson
left a comment
There was a problem hiding this comment.
Looks good, but let's simplify this a bit.
| ScriptThreadMessage::ForceGC => { | ||
| unsafe { | ||
| JS_GC(*GlobalScope::get_cx(), GCReason::API); | ||
| } | ||
| // Notify the constellation that this script thread's GC is complete. | ||
| // Use dummy values for webview_id and pipeline_id since the values | ||
| // don't matter in that case. | ||
| let _ = self.senders.pipeline_to_constellation_sender.send(( | ||
| base::id::TEST_WEBVIEW_ID, | ||
| base::id::PipelineId::new(), | ||
| ScriptToConstellationMessage::ForceGCCompleted, | ||
| )); | ||
| }, |
There was a problem hiding this comment.
As this can fail, I think it's better to make this API even simpler. Instead of making this API return a promise, let's just let it happen asynchronously. The user can then just wait for the new memory results to settle. It's not quite as nice, but it's also a bit less of a lie. Opening a new tab or closing one could cause really weird behavior otherwise.
1670183 to
ad9de9a
Compare
ServoIternals.garbageCollectAllContexts()
ServoIternals.garbageCollectAllContexts()ServoInternals.garbageCollectAllContexts()
This is useful in about:memory to measure memory usage after running the GC. The calling page sends a callback to the constellation that in turn wait for all script threads to run the GC and report back. Signed-off-by: webbeef <me@webbeef.org>
ad9de9a to
2f42e28
Compare
|
@mrobinson can you send that to the merge queue? |
This is useful in about:memory to measure memory usage after running the GC. The calling page sends a callback to the constellation that in turn wait for all script threads to run the GC and report back. Testing: Manual testing in `about:memory` Before running GC: <img width="2048" height="1480" alt="Screenshot from 2026-02-23 18-50-46" src="https://github.com/user-attachments/assets/fd8399c1-fbc7-4f4c-886d-f29629ef8369" /> After running GC: <img width="2048" height="1480" alt="Screenshot from 2026-02-23 18-51-00" src="https://github.com/user-attachments/assets/82c793f7-8229-4de4-9cb5-47c94383b410" /> Signed-off-by: webbeef <me@webbeef.org>
This is useful in about:memory to measure memory usage after running the GC. The calling page sends a callback to the constellation that in turn wait for all script threads to run the GC and report back. Testing: Manual testing in `about:memory` Before running GC: <img width="2048" height="1480" alt="Screenshot from 2026-02-23 18-50-46" src="https://github.com/user-attachments/assets/fd8399c1-fbc7-4f4c-886d-f29629ef8369" /> After running GC: <img width="2048" height="1480" alt="Screenshot from 2026-02-23 18-51-00" src="https://github.com/user-attachments/assets/82c793f7-8229-4de4-9cb5-47c94383b410" /> Signed-off-by: webbeef <me@webbeef.org>
This is useful in about:memory to measure memory usage after running the GC.
The calling page sends a callback to the constellation that in turn wait for all script threads to run the GC and report back.
Testing: Manual testing in
about:memoryBefore running GC:
After running GC: