Opened on 04/06/2018 at 05:30:04 AM

Closed on 12/17/2019 at 03:15:24 AM

#6559 closed change (fixed)

Use maps and sets where appropriate

Reported by: mjethani Assignee: mjethani
Priority: P2 Milestone:
Module: Core Keywords:
Cc: kzar, sergz, jsonesen, greiner Blocked By:
Blocking: #6425, #6753 Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Ross Verified working: yes
Review URL(s):

https://codereview.adblockplus.org/29743730/
https://codereview.adblockplus.org/29745555/
https://codereview.adblockplus.org/29800557/
https://codereview.adblockplus.org/29802587/
https://codereview.adblockplus.org/29852555/

Description (last modified by mjethani)

Background

Core uses an object with a null prototype for a map or a set in a few places. For example, in lib/elemHideEmulation.js:

let filters = Object.create(null);

function addFilter(filter)
{
  filters[filter.text] = true;
}

With the upgrade to ES2015 the code could use Map and Set objects instead.

What to change

In lib/downloader.js, convert _downloading to a Set.

In lib/elemHide.js, convert filterKeyBySelector and exceptions each to a Map, convert knownExceptions to a Set.

In lib/elemHideEmulation.js, convert filters to a Set.

In lib/filterStorage.js, convert FilterStorage.knownSubscriptions to a Map.

In lib/subscriptionClasses.js, convert Subscription.knownSubscriptions to a Map.

In lib/subscriptionClasses.js, convert SpecialSubscription.defaultsMap to a Map.

In lib/filterClasses.js, convert Filter.prototype.subscriptions to a Set.

Integration notes

With changeset 212fe705ab82, FilterStorage.knownSubscriptions is now a Map object (#6739).

With changeset ae6bf93f1856, the type of SpecialSubscription.defaultsMap is now Map rather than Object.

With changeset 03c07a4ba673, the type of the subscriptions property of the Filter class is Set rather than Array. This would require a change in UI in messageResponder.js (and possibly elsewhere) (#6876) and in the extension in lib/whitelisting.js.

Hints for testers

Test that the downloading and loading of subscriptions works correctly.

Test that element hiding and element hiding emulation filters, with and without exceptions, work correctly.

Test that filters from all types of subscriptions are loaded and saved correctly. For example, add only one filter ##.foo to the "My filters" box; then restart the browser; the filter should still be there. Try with multiple filters. Likewise, pick random filters from EasyList+AA to try out between browser restarts and see that the filters always work.

Attachments (0)

Change History (37)

comment:1 Changed on 04/06/2018 at 07:42:07 AM by sergz

JIC, it's absolutely fine for me and I like to see the work in that direction, however as the next step (it should not be a blocker) it will be very interesting to measure how it affects the memory consumption. In that regard I would like to note that one should rather pay attention to measure not mere JS heap but also RSS, what is essential for us.

comment:2 Changed on 04/06/2018 at 02:36:57 PM by abpbot

A commit referencing this issue has landed:
Issue 6559 - Use maps and sets where appropriate

comment:3 Changed on 04/06/2018 at 03:16:04 PM by kzar

I'm seeing some filterListener.js test failures since that last commit Manish, could you take a look?

comment:4 Changed on 04/08/2018 at 05:26:03 AM by abpbot

A commit referencing this issue has landed:
Issue 6559 - Fix tests for changeset 662384d3b0ad

comment:5 Changed on 04/08/2018 at 05:27:30 AM by mjethani

  • Review URL(s) modified (diff)

comment:6 Changed on 06/04/2018 at 08:36:29 PM by jsonesen

  • Resolution set to fixed
  • Status changed from new to closed

comment:7 follow-up: Changed on 06/05/2018 at 05:10:44 PM by kzar

  • Cc jsonesen added
  • Priority changed from Unknown to P3

I still see more instances of Object.create(null) in the core code, did you check that none of those can be converted to Maps / Sets before closing?

comment:8 in reply to: ↑ 7 Changed on 06/05/2018 at 06:53:12 PM by jsonesen

Replying to kzar:

I still see more instances of Object.create(null) in the core code, did you check that none of those can be converted to Maps / Sets before closing?

closed it on accident, I meant to set it as reviewing.

comment:9 Changed on 06/06/2018 at 10:44:30 AM by kzar

  • Resolution fixed deleted
  • Status changed from closed to reopened

Ah right, no worries. I'll reopen in that case.

comment:10 Changed on 06/06/2018 at 11:12:46 AM by mjethani

  • Review URL(s) modified (diff)

comment:11 Changed on 06/07/2018 at 02:43:05 PM by abpbot

A commit referencing this issue has landed:
Issue 6559 - Use Map object for known subscriptions

comment:12 Changed on 06/07/2018 at 02:50:49 PM by mjethani

Reported #6739 in UI for the last change.

comment:13 Changed on 06/12/2018 at 07:07:46 PM by abpbot

A commit referencing this issue has landed:
Issue 6559 - Change SpecialSubscription.defaultsMap to Map object

comment:14 Changed on 06/12/2018 at 07:09:58 PM by mjethani

  • Description modified (diff)

comment:15 Changed on 06/13/2018 at 07:28:56 AM by mjethani

  • Description modified (diff)
  • Review URL(s) modified (diff)

comment:16 Changed on 06/13/2018 at 07:29:20 AM by mjethani

  • Priority changed from P3 to P2
  • Ready set

comment:17 Changed on 06/13/2018 at 07:29:29 AM by mjethani

  • Status changed from reopened to reviewing

comment:18 Changed on 06/13/2018 at 07:32:08 AM by mjethani

  • Description modified (diff)

comment:19 Changed on 06/13/2018 at 12:31:59 PM by greiner

  • Blocking 6739 added

comment:20 Changed on 06/20/2018 at 09:42:36 AM by wspee

  • Blocking 6753 added

comment:21 Changed on 07/18/2018 at 12:21:03 PM by greiner

  • Blocking 6739 removed

comment:22 Changed on 07/20/2018 at 11:43:21 AM by mjethani

  • Description modified (diff)

comment:23 Changed on 08/10/2018 at 02:11:55 PM by mjethani

  • Description modified (diff)

comment:24 Changed on 08/10/2018 at 02:19:43 PM by mjethani

  • Review URL(s) modified (diff)

comment:25 Changed on 08/15/2018 at 06:57:28 PM by abpbot

comment:26 Changed on 08/15/2018 at 07:14:02 PM by mjethani

  • Description modified (diff)

comment:27 follow-ups: Changed on 08/15/2018 at 07:15:26 PM by mjethani

  • Cc greiner added

@greiner Filter.prototype.subscriptions is a Set object now. You would have to make a change in UI in messageResponder.js and possibly elsewhere.

Last edited on 08/15/2018 at 07:16:07 PM by mjethani

comment:28 in reply to: ↑ 27 Changed on 08/15/2018 at 07:19:50 PM by mjethani

Replying to mjethani:

@greiner Filter.prototype.subscriptions is a Set object now.

This would also require a change in the web extension in lib/whitelisting.js.

comment:29 Changed on 08/21/2018 at 11:44:52 AM by Ross

  • Tester changed from Unknown to Ross
  • Verified working set

Done. Subscription downloading, element hiding and emulation filters (with exceptions), and storing of filters seem to be working as expected.

ABP 3.2.0.2103
Chrome 68 / 55 / 49 / Windows 10
Firefox 61 / 55 / 51 / Windows 10

comment:30 in reply to: ↑ 27 ; follow-up: Changed on 08/21/2018 at 04:29:49 PM by greiner

Replying to mjethani:

@greiner Filter.prototype.subscriptions is a Set object now. You would have to make a change in UI in messageResponder.js and possibly elsewhere.

I've created #6876 to apply that change to adblockplusui. Is this change going to be included in the very next extension release already?

comment:31 in reply to: ↑ 30 Changed on 08/22/2018 at 06:23:24 AM by mjethani

Replying to greiner:

Replying to mjethani:

@greiner Filter.prototype.subscriptions is a Set object now. You would have to make a change in UI in messageResponder.js and possibly elsewhere.

I've created #6876 to apply that change to adblockplusui. Is this change going to be included in the very next extension release already?

It should be in the next proper release (3.4), but not in the next "snippets-only" or hotfix release (3.3.x). If by "very next" you meant 3.3, then no.

comment:32 Changed on 08/22/2018 at 06:25:45 AM by mjethani

  • Description modified (diff)

comment:33 Changed on 08/22/2018 at 06:27:14 AM by mjethani

  • Description modified (diff)

comment:34 Changed on 03/16/2019 at 03:48:35 PM by mjethani

The work here is done. I am closing this ticket.

comment:35 Changed on 03/16/2019 at 03:48:46 PM by mjethani

  • Resolution set to fixed
  • Status changed from reviewing to closed

comment:36 Changed on 12/17/2019 at 03:14:59 AM by mjethani

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:37 Changed on 12/17/2019 at 03:15:24 AM by mjethani

  • Resolution set to fixed
  • Status changed from reopened to closed

Add Comment

Modify Ticket

Change Properties
Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from mjethani.
 
Note: See TracTickets for help on using tickets.