Skip to content

Commit 6ed661f

Browse files
perf: Use cheaper guard to determine if message is a notification (#3352)
When handling notifications on the command stream we already know that the values are valid JSON, therefore we can use `hasProperty` as a type guard instead of validating the notification entirely.
1 parent 8682f27 commit 6ed661f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/snaps-controllers/src/services/AbstractExecutionService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import type {
1313
import {
1414
Duration,
1515
assertIsJsonRpcRequest,
16+
hasProperty,
1617
inMilliseconds,
1718
isJsonRpcFailure,
18-
isJsonRpcNotification,
1919
isObject,
2020
} from '@metamask/utils';
2121
import { nanoid } from 'nanoid';
@@ -278,7 +278,7 @@ export abstract class AbstractExecutionService<WorkerType>
278278
| JsonRpcRequest
279279
| JsonRpcNotification<Json[] | Record<string, Json>>,
280280
) => {
281-
if (!isJsonRpcNotification(message)) {
281+
if (hasProperty(message, 'id')) {
282282
return;
283283
}
284284

0 commit comments

Comments
 (0)