Opened on 11/02/2018 at 09:40:41 PM

Closed on 11/18/2018 at 03:34:54 AM

Last modified on 11/21/2018 at 04:27:51 AM

#7095 closed change (rejected)

Remove unused filter state properties

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

Description (last modified by mjethani)

Background

There are currently three properties of the Filter class that keep client-side state for a filter: disabled, hitCount, and lastHit. These properties are no longer being used in the browser extension for Chrome, Firefox, and Opera. Because of these properties, it is not entirely possible to lose references to Filter objects (#7094) (because the state would be lost).

If these properties are not being used on any product based on the core library, we should remove them. It would allow us to make some more optimizations.

Resolution

Based on the discussion in this ticket, we have decided not to remove these properties as they may be needed in the future. Instead, objects with some state will be persisted in memory. It should still be possible to do the optimization in #7097 for most filter objects.

Attachments (0)

Change History (17)

comment:1 Changed on 11/02/2018 at 09:42:11 PM by mjethani

  • Description modified (diff)

comment:2 Changed on 11/02/2018 at 09:42:26 PM by mjethani

  • Summary changed from Remove unused filter client-side state properties to Remove unused filter state properties

comment:3 Changed on 11/02/2018 at 09:42:51 PM by mjethani

@greiner @sebastian any thoughts?

comment:4 Changed on 11/02/2018 at 09:43:34 PM by mjethani

  • Description modified (diff)

comment:5 Changed on 11/02/2018 at 10:15:12 PM by sebastian

If we can get rid of those properties, the memory and disk usage improvements will probably be significant, as most boilerplate in the serialized filter data come from persisting these properties.

comment:6 Changed on 11/03/2018 at 09:49:23 PM by mjethani

  • Cc sergz added

comment:7 Changed on 11/03/2018 at 10:10:52 PM by mjethani

  • Blocking 7097 added

comment:8 Changed on 11/03/2018 at 10:18:24 PM by mjethani

  • Blocking 7094 removed

comment:9 Changed on 11/03/2018 at 10:38:49 PM by mjethani

The plan is to make filter objects stateless and then ephemeral (#7097), at least the most lightweight of them. In the case of ElemHideFilter instances, we don't need them at all, because we are storing all the same information in lib/elemHide.js. For RegExpFilter instances with a literal string pattern (#7052), we don't need those objects either.

Regarding the statefulness of these objects, I already have a solution for Filter.prototype.subscriptions (#7096).

Now I'd like to know if anyone has any objections about removing the above three properties. They are not being used in the Chrome and Firefox extension, from what I can tell.

Last edited on 11/03/2018 at 10:39:28 PM by mjethani

comment:10 Changed on 11/05/2018 at 01:15:29 PM by greiner

We're going to need the "disabled" property for the UI to show whether a given filter is disabled and to allow users to en-/disable it. This is part of the new custom filters editor table that will be included in the next release.

Also note that en-/disabling the extension on a page may cause filters in downloadable filter lists to get disabled.

The other two properties aren't being populated at this point so removing those shouldn't affect us AFAIK but they would be interesting for use in that same table as well as for the opt-in data collection we're planning to add.

comment:11 Changed on 11/05/2018 at 02:26:25 PM by mjethani

Are only user-defined filters supposed to be disabled? If it's for downloadable filters too, then is it per subscription or across all subscriptions?

comment:12 Changed on 11/05/2018 at 03:02:07 PM by greiner

For the custom filters table it should be sufficient if only the filter within the custom subscription gets disabled.

For reenabling the extension, however, a filter is expected to be disabled across all subscriptions (see adblockpluschrome/lib/whitelisting.js), regardless of whether or not it was added by the user.

comment:13 Changed on 11/05/2018 at 03:10:55 PM by mjethani

Oh, I see.

For disabled filters, we could just maintain a separate list and put them there. At the time of serialization, we could write them out as normal. I'll see if this is feasible and makes sense.

So instead of all filter objects being stateless, the code would have to distinguish between the objects that have any state and then just leave them alone instead of removing them from memory. This is fine. We could still benefit from this optimization a lot for most filters.

comment:14 Changed on 11/18/2018 at 03:32:05 AM by mjethani

  • Blocking 7097 removed

comment:15 Changed on 11/18/2018 at 03:34:54 AM by mjethani

  • Description modified (diff)
  • Resolution set to rejected
  • Status changed from new to closed

comment:16 Changed on 11/20/2018 at 08:26:09 PM by kzar

I wonder if we could create a WeakMap of disabled filters, then use that from a disabled getter in the Filter instances?

comment:17 Changed on 11/21/2018 at 04:27:51 AM by mjethani

Yeah, something like that.

It depends on which other parts of the code are holding on to the Filter instances. If there are no other references to the object, then it would just have to be a Map (otherwise even this last reference would be lost). Essentially, I think that Filter.knownFilters could hold on to any Filter instances that have any state at all, but leave all the other Filter instances out - they can be created on demand (transparently to the caller). In most cases we don't need Filter objects at all, just the text (#7097).

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 (none).
 
Note: See TracTickets for help on using tickets.