Skip to content

Commit

Permalink
Bug 1822293 - [devtools] Clear exceptions reducer on each thread remo…
Browse files Browse the repository at this point in the history
…val. r=devtools-reviewers,nchevobbe

This help reduce memory footprint, especially in the MBT,
but will also help stop clearing all reducers on navigation.

Differential Revision: https://phabricator.services.mozilla.com/D175331
  • Loading branch information
ochameau committed Apr 14, 2023
1 parent 186f38e commit 6749657
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions devtools/client/debugger/src/actions/exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function addExceptionFromResources(resources) {
sourceActorId: sourceId,
errorMessage,
stacktrace,
threadActorId: resource.targetFront.targetForm.threadActor,
};

dispatch(addException(exception));
Expand Down
26 changes: 24 additions & 2 deletions devtools/client/debugger/src/reducers/exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ function update(state = initialExceptionsState(), action) {
switch (action.type) {
case "ADD_EXCEPTION":
return updateExceptions(state, action);
case "REMOVE_THREAD": {
return removeExceptionsFromThread(state, action);
}
}
return state;
}

function updateExceptions(state, action) {
const { mutableExceptionsMap } = state;
const { exception } = action;
const { sourceActorId } = exception;

let exceptions = state.mutableExceptionsMap.get(sourceActorId);
let exceptions = mutableExceptionsMap.get(sourceActorId);
if (!exceptions) {
exceptions = [];
state.mutableExceptionsMap.set(sourceActorId, exceptions);
mutableExceptionsMap.set(sourceActorId, exceptions);
}

// As these arrays are only used by getSelectedSourceExceptions selector method,
Expand All @@ -43,4 +47,22 @@ function updateExceptions(state, action) {
};
}

function removeExceptionsFromThread(state, action) {
const { mutableExceptionsMap } = state;
const { threadActorID } = action;
const sizeBefore = mutableExceptionsMap.size;
for (const [sourceActorId, exceptions] of mutableExceptionsMap) {
// All exceptions relates to the same source actor, and so, the same thread actor.
if (exceptions[0].threadActorId == threadActorID) {
mutableExceptionsMap.delete(sourceActorId);
}
}
if (sizeBefore != mutableExceptionsMap.size) {
return {
...state,
};
}
return state;
}

export default update;

0 comments on commit 6749657

Please sign in to comment.