Skip to content

Commit

Permalink
Use Set to improve lookup performance (#1086)
Browse files Browse the repository at this point in the history
<!--
Thanks for your contribution!

Please ensure that any applicable requirements below are satisfied
before submitting this pull request. This will help ensure a quick and
efficient review cycle.
-->

**Improve lookup time in PhishingController**

This PR creates a Set from `metamaskConfig.blocklist` in the
`PhishingController`. The blocklist Set is later used as a lookup inside
of a filter method. As a result, look up performance is significantly
improved by using a `Set` + `has` method instead of `includes` method
from an Array.

**Description**

_Itemize the changes you have made into the categories below_

- CHANGED:

  - `PhishingController.updatePhishingLists`
- Create a `Set` from `metamaskConfig.blocklist` to be used as lookup.

**Checklist**

- [x] Tests are included if applicable
- [x] Any added code is fully documented

**Issue**

Resolves MetaMask/metamask-mobile#5382
  • Loading branch information
Cal-L authored and MajorLift committed Oct 11, 2023
1 parent d3ecdd3 commit 026f0ca
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/phishing-controller/src/PhishingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,14 @@ export class PhishingController extends BaseController<
configs.push(metamaskConfig);
}

// Create Set from metamaskConfig.blocklist to improve look up performance when used within filter.
const mmConfigBlocklist = new Set(metamaskConfig.blocklist);

// Correctly shaping PhishFort config.
const phishfortConfig: EthPhishingDetectConfig = {
allowlist: [],
blocklist: (phishfortHotlist || []).filter(
(i) => !metamaskConfig.blocklist.includes(i),
(i) => !mmConfigBlocklist.has(i),
), // Removal of duplicates.
fuzzylist: [],
tolerance: 0,
Expand Down

0 comments on commit 026f0ca

Please sign in to comment.