Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Use JSON for default.rulesets instead of XML - #12273

Merged
Hainish merged 9 commits into
EFForg:masterfrom
cschanaj:fix-ruleset-loading
Sep 5, 2017
Merged

Use JSON for default.rulesets instead of XML#12273
Hainish merged 9 commits into
EFForg:masterfrom
cschanaj:fix-ruleset-loading

Conversation

@cschanaj

@cschanaj cschanaj commented Aug 31, 2017

Copy link
Copy Markdown
Collaborator

ping @Hainish

P.S. please do not feel obligated to merge before the next release.

@ghost

ghost commented Aug 31, 2017

Copy link
Copy Markdown

@cschanaj You may be interested in https://github.com/koops76/https-everywhere-rules.

@ghost

ghost commented Aug 31, 2017

Copy link
Copy Markdown

@Hainish @cschanaj I will extend on this PR, since I have a few ideas, specifically for xml2json Node script.

@ghost

ghost commented Aug 31, 2017

Copy link
Copy Markdown

@cschanaj cschanaj#10

@ghost

ghost commented Aug 31, 2017

Copy link
Copy Markdown

@cschanaj Opening all files at the same time may cause Node to run out of file handles on Windows. Will fix in a PR.

@cschanaj

Copy link
Copy Markdown
Collaborator Author

@Hainish For unknown reason, I got the following error message on Firefox 55.0.3 from the Browser Console despite the fact that I have not modify the file loading code. Do you have any suggestion?

P.S. The extension seems to work on Chromium now..
P.S. The colored part in the file URL is the current username.

@ghost

ghost commented Aug 31, 2017

Copy link
Copy Markdown

@cschanaj You missed one of the places where rulesets file is loaded. See https://github.com/cschanaj/https-everywhere/pull/10/files#diff-81d05cf2685349d7bbbe9f394bd74506L652.

@cschanaj

cschanaj commented Aug 31, 2017

Copy link
Copy Markdown
Collaborator Author

@koops76 fixed travis now. thanks! @Hainish the error still presist when installing the extension via the compile XPI file from makexpi.sh, but the extension is working now, why?

P.S. Feel free to review and merge this after testing. thanks!

@ghost

ghost commented Sep 1, 2017

Copy link
Copy Markdown

@cschanaj Can you review my changes? Just wait until I will recreate the PR.

@cschanaj

cschanaj commented Sep 1, 2017

Copy link
Copy Markdown
Collaborator Author

@koops76 specifically, what changes?

@ghost

ghost commented Sep 1, 2017

Copy link
Copy Markdown

@cschanaj https://github.com/cschanaj/https-everywhere/pull/11
Not sure why some of your changes are also in here.

@ghost

ghost commented Sep 1, 2017

Copy link
Copy Markdown

Feel free to not merge but copy the changes partially.

@cschanaj

cschanaj commented Sep 1, 2017

Copy link
Copy Markdown
Collaborator Author

Not sure why some of your changes are also in here.

this is because you created your branch from cschanaj/master instead of cschanaj/fix-ruleset-loading

@ghost

ghost commented Sep 1, 2017

Copy link
Copy Markdown

@cschanaj Nope: git checkout -b fix-ruleset-loading cschanaj/fix-ruleset-loading

@ghost

ghost commented Sep 1, 2017

Copy link
Copy Markdown

@cschanaj Fixed: https://github.com/cschanaj/https-everywhere/pull/12

@cschanaj

cschanaj commented Sep 1, 2017

Copy link
Copy Markdown
Collaborator Author

@koops76 please update the rewriter/rewrite.js in a separate PR. this is important but I don't want to include it here. thanks !!

@ghost

ghost commented Sep 1, 2017

Copy link
Copy Markdown

@cschanaj ok

@ghost

ghost commented Sep 1, 2017

Copy link
Copy Markdown

@cschanaj Done.

@cschanaj

cschanaj commented Sep 1, 2017

Copy link
Copy Markdown
Collaborator Author

ping @Hainish this is ready for a review and merging. Simple benchmark shown that this reduce startup time (<1.5 seconds, 1.35 seconds on my machine) and memory usage (<100mb) effectively. thanks!

Comment thread utils/merge-rulesets.py

# We make default.rulesets at build time,
# but it shouldn't have a variable timestamp
subprocess.call(["touch", "-r", "src/install.rdf", ofn])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer needed, install.rdf is going away with WebExtensions transition.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is intended to remove the timestamp of default.rulesets. If src/install.rdf is gone, we will need another for timestamp reference. Let's see if Hainish would like to keep this line and suggest another file for timestamp reference.

P.S. Python because this will introduce fewer changes, I assume this will speed up the review process. thanks.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cschanaj Still all Python scripts will be replaced by Node scripts soon.

@ghost

ghost commented Sep 1, 2017

Copy link
Copy Markdown

Also why Python?

@Hainish

Hainish commented Sep 1, 2017

Copy link
Copy Markdown
Member

@cowlicks let's review this together.

@Hainish Hainish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my comments, lgtm.

This is great, a huge performance and memory benefit. Great job!

Comment thread chromium/rules.js
}
},

parseOneJsonRuleset: function(ruletag) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correspondingly, let's change the other one to parseOneXmlRuleset

Comment thread chromium/rules.js
log(WARN, 'Error processing ruleset:' + e);
}
}
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a counter to iterate rather than

for (let ruleset of ruleJson) {
  try {
    this.parseOneJsonRuleset(ruleset);
  } catch(e) {
    log(WARN, 'Error processing ruleset:' + e);
  }
}

Comment thread chromium/rules.js Outdated

var rules = ruletag["rule"];
for (let i in rules) {
let rule = rules[i];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not rule of rules?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not iterable, even though it should be.

Comment thread chromium/rules.js Outdated
}

var exclusions = ruletag["exclusion"];
for (let i in exclusions) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not exclusion of exclusions?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not iterable, even though it should be.

Comment thread chromium/rules.js Outdated

var cookierules = ruletag["securecookie"];
for (let i in cookierules) {
let cookierule = cookierules[i];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not cookierule of cookierules?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not iterable, even though it should be.

Comment thread chromium/rules.js Outdated

var targets = ruletag["target"];
for (let i in targets) {
let target = targets[i];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not target of targets?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not iterable, even though it should be.

Comment thread utils/merge-rulesets.py
subprocess.call(["touch", "-r", "src/install.rdf", ofn])

# Everything is okay.
print(" * Everything is Okay.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

@cowlicks

cowlicks commented Sep 1, 2017

Copy link
Copy Markdown
Contributor

I parsed master and this branch with:

function getJson() {
  out = [];
  all_rules.targets.forEach((k, target) => {
    out.push(JSON.stringify(target));
  });
  return out.toString();
}

And they look the same to me. Output is here.

@ghost

ghost commented Sep 2, 2017

Copy link
Copy Markdown

I think non-iterable arrays should either be iterated using forEach or for (let i; i < array.length; i++) loop, not for (const i in array) loop.

@cschanaj

cschanaj commented Sep 2, 2017

Copy link
Copy Markdown
Collaborator Author

@Hainish @koops76 checking through the code, I find that the console throw non-iterable error because ruletag.exclusion and ruletag.securecookie can be undefined when a ruleset does not specify the tags. Fixed by adding a conditional if. thanks!!

@ghost

ghost commented Sep 2, 2017

Copy link
Copy Markdown

@cschanaj Always check if the array is undefined before attempting iteration.

@cschanaj

cschanaj commented Sep 2, 2017

Copy link
Copy Markdown
Collaborator Author

Was fixed in d437c69

@cowlicks

cowlicks commented Sep 2, 2017

Copy link
Copy Markdown
Contributor

Huge memory improvements on startup here, with this PR, from chrome://system > mem_usage I get:

Extension [HTTPS Everywhere] 112 MB private, 56 MB shared, -1 FDs open of 1024

On master I get:

Extension [HTTPS Everywhere] 217 MB private, 57 MB shared, -1 FDs open of 1024

Where is this coming from? I'm guessing the DOM nodes from the original xml files are not cleaned up for a while.

Also worth noting, in my normal long-running browser session, I'm running HTTPS Everywhere : version 2017_8_31 and its memory usage is Extension [HTTPS Everywhere] 126 MB private, 63 MB shared, -1 FDs open of 1024. So the memory usage on master does decrease over time.

@ghost

ghost commented Sep 2, 2017

Copy link
Copy Markdown

@Hainish Does radix tree look like this:

{
  "com": {
    "example": {
      "^": true,
      "www": { "^": true }
  },
  "net": {
    "example": {
      "^": true,
      "www": { "^": true }
  },
  "org": {
    "eff": {
      "^": true,
      "www": { "^": true }
  },
  "onion": {
    "exampleexampleex": { "^": true }
  }
}

@Hainish

Hainish commented Sep 5, 2017

Copy link
Copy Markdown
Member

Great, this looks good to me. Merging

@Hainish
Hainish merged commit 06b50fd into EFForg:master Sep 5, 2017
@cschanaj

cschanaj commented Sep 6, 2017

Copy link
Copy Markdown
Collaborator Author

@Hainish please also take a look at #12422 (memory leak) and #12452 (partial information leak) when you have the time. Thank!

@cschanaj
cschanaj deleted the fix-ruleset-loading branch September 6, 2017 11:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants