mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-08-17 18:25:42 +02:00
[eric] perf: mass-delete parallel-detaches browsers too (removeBrowserCardsCleanly); flat latency, same crash-safe ordering
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { closeSession } from '@/shared/state/agentsSlice';
|
||||
import { removeNote, removeWorkflowCard, closeWorkflowsHub, recordClosedCard } from '@/shared/state/dashboardLayoutSlice';
|
||||
import { closeWorkflowCard } from '@/shared/state/workflowsSlice';
|
||||
import { removeBrowserCardCleanly } from '@/shared/browserTeardown';
|
||||
import { removeBrowserCardsCleanly } from '@/shared/browserTeardown';
|
||||
import { removeViewCardCleanly } from '@/shared/viewTeardown';
|
||||
import type { AppDispatch } from '@/shared/state/store';
|
||||
import type { CardType } from '../state/useDashboardSelection';
|
||||
@@ -36,6 +36,6 @@ export function deleteSelectedCards(selectedIds: Map<string, CardType>, dispatch
|
||||
// "non-existent mailbox" errors and SIGSEGVs the GPU/browser process (the mass-delete self-quit).
|
||||
void (async () => {
|
||||
for (const id of viewIds) await removeViewCardCleanly(id, dispatch);
|
||||
for (const id of browserIds) await removeBrowserCardCleanly(id, dispatch);
|
||||
await removeBrowserCardsCleanly(browserIds, dispatch);
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -38,3 +38,17 @@ export async function removeBrowserCardCleanly(
|
||||
forgetBrowser(browserId);
|
||||
dispatch(removeBrowserCard(browserId));
|
||||
}
|
||||
|
||||
// Batch remove: detach every browser's CDP in PARALLEL (order-independent, the only invariant is
|
||||
// all debuggers gone before any unmount), THEN remove them. Serial detach cost ~72ms/browser, so a
|
||||
// 20-card multi-select delete lagged over a second; this keeps the crash-safe ordering but flat.
|
||||
export async function removeBrowserCardsCleanly(
|
||||
browserIds: string[],
|
||||
dispatch: Dispatch,
|
||||
): Promise<void> {
|
||||
await Promise.allSettled(browserIds.map((id) => detachBrowserCdp(id)));
|
||||
for (const id of browserIds) {
|
||||
forgetBrowser(id);
|
||||
dispatch(removeBrowserCard(id));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user