diff --git a/README.md b/README.md index bb30048..23c9395 100755 --- a/README.md +++ b/README.md @@ -17,27 +17,3 @@ My maxim is _"Your freedom ends when it starts to confine the freedom of others" Looking at how Russian government [distorts TV](https://therussianreader.wordpress.com/2015/11/22/russian-truckers-strike-dagestan/) and blocks [critics of Putin](http://www.reuters.com/article/2014/03/13/us-russia-internet-idUSBREA2C21L20140313), I decided to write an anti-censorship extension for Chromium before they strike me first. - -## PAC-Script Performance Analysis - -```javascript -if (Is_subdomain_of( host, blocked_hosts )) - return 'use proxy'; -``` - -You have to make `Is_subdomain_of` very fast. -This check is executed on each request. You should watch memeory consumption too. - -The naive solution is to keep array of blocked ips and check if the host resolves to one of the ips. -You may do it with `indexOf`, binary search, etc. -The shortcoming of every ip solution is that __some providers resolve blocked hosts to wrong ips__, so we eventually need list of hosts. - -I have tested different solutions, and depicted [results](./benchmark/Output.txt) in the following chart: - -![Host Lookup Chart: Time-Memory, Hits-Misses](./chart/host-lookup-chart.png) - -* __IPs indexOf__ – Blocked IP is searched by `indexOf` -* __IPs binary__ – Blocked IP is searched by binary search. For some reason miss time slightly increased. -* __IPs switch__ – Simply `switch(Blocked_IP) { case1: ... caseN: return true }`. Works even better than binary search. Magic. -* __Hosts switch__ – Radix trie built on `switch`. Comparable to __IPs switch__. - diff --git a/pac-script-performance-analyses/README.md b/pac-script-performance-analyses/README.md new file mode 100755 index 0000000..8014374 --- /dev/null +++ b/pac-script-performance-analyses/README.md @@ -0,0 +1,25 @@ +## PAC-Script Performance Analysis + +Somewhere in PAC-script you may want: + +```javascript +if (Is_subdomain_of( host, blocked_hosts )) + return 'use proxy'; +``` + +You have to make `Is_subdomain_of` very fast. +This check is executed on each request. You should watch memeory consumption too. + +The naive solution is to keep array of blocked ips and check if the host resolves to one of the ips. +You may do it with `indexOf`, binary search, etc. +The shortcoming of every ip solution is that __some providers resolve blocked hosts to wrong ips__, so we eventually need list of hosts. + +I have tested different solutions, and depicted [results](./benchmark/Output.txt) in the following chart: + +![Host Lookup Chart: Time-Memory, Hits-Misses](./chart/host-lookup-chart.png) + +* __IPs indexOf__ – Blocked IP is searched by `indexOf` +* __IPs binary__ – Blocked IP is searched by binary search. For some reason miss time slightly increased. +* __IPs switch__ – Simply `switch(Blocked_IP) { case1: ... caseN: return true }`. Works even better than binary search. Magic. +* __Hosts switch__ – Radix trie built on `switch`. Comparable to __IPs switch__. + diff --git a/benchmark/.gitignore b/pac-script-performance-analyses/benchmark/.gitignore similarity index 100% rename from benchmark/.gitignore rename to pac-script-performance-analyses/benchmark/.gitignore diff --git a/benchmark/Inputs/blocked-hosts.txt b/pac-script-performance-analyses/benchmark/Inputs/blocked-hosts.txt similarity index 100% rename from benchmark/Inputs/blocked-hosts.txt rename to pac-script-performance-analyses/benchmark/Inputs/blocked-hosts.txt diff --git a/benchmark/Inputs/blocked-ips.txt b/pac-script-performance-analyses/benchmark/Inputs/blocked-ips.txt similarity index 100% rename from benchmark/Inputs/blocked-ips.txt rename to pac-script-performance-analyses/benchmark/Inputs/blocked-ips.txt diff --git a/benchmark/Inputs/missed.txt b/pac-script-performance-analyses/benchmark/Inputs/missed.txt similarity index 100% rename from benchmark/Inputs/missed.txt rename to pac-script-performance-analyses/benchmark/Inputs/missed.txt diff --git a/benchmark/Output.txt b/pac-script-performance-analyses/benchmark/Output.txt similarity index 100% rename from benchmark/Output.txt rename to pac-script-performance-analyses/benchmark/Output.txt diff --git a/benchmark/Program.cs b/pac-script-performance-analyses/benchmark/Program.cs similarity index 100% rename from benchmark/Program.cs rename to pac-script-performance-analyses/benchmark/Program.cs diff --git a/benchmark/Proxy.cs b/pac-script-performance-analyses/benchmark/Proxy.cs similarity index 100% rename from benchmark/Proxy.cs rename to pac-script-performance-analyses/benchmark/Proxy.cs diff --git a/benchmark/Win32Api.cs b/pac-script-performance-analyses/benchmark/Win32Api.cs similarity index 100% rename from benchmark/Win32Api.cs rename to pac-script-performance-analyses/benchmark/Win32Api.cs diff --git a/benchmark/project.json b/pac-script-performance-analyses/benchmark/project.json similarity index 100% rename from benchmark/project.json rename to pac-script-performance-analyses/benchmark/project.json diff --git a/benchmark/project.lock.json b/pac-script-performance-analyses/benchmark/project.lock.json similarity index 100% rename from benchmark/project.lock.json rename to pac-script-performance-analyses/benchmark/project.lock.json diff --git a/chart/README.md b/pac-script-performance-analyses/chart/README.md similarity index 100% rename from chart/README.md rename to pac-script-performance-analyses/chart/README.md diff --git a/chart/host-lookup-chart.png b/pac-script-performance-analyses/chart/host-lookup-chart.png similarity index 100% rename from chart/host-lookup-chart.png rename to pac-script-performance-analyses/chart/host-lookup-chart.png diff --git a/chart/src/data.tsv b/pac-script-performance-analyses/chart/src/data.tsv similarity index 100% rename from chart/src/data.tsv rename to pac-script-performance-analyses/chart/src/data.tsv diff --git a/chart/src/index.html b/pac-script-performance-analyses/chart/src/index.html similarity index 100% rename from chart/src/index.html rename to pac-script-performance-analyses/chart/src/index.html diff --git a/package.json b/package.json index 816f153..d2b460d 100755 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "generate": "cd pac-generator && npm start", "prestart": "npm run generate", "start": "npm run bench", - "bench": "cd Benchmark && dnx run ../pac-generator/generated-PACs", + "bench": "cd ./pac-script-performance-analyses/benchmark && dnx run ../../pac-generator/generated-PACs", "test": "rm -r pac-generator/generated-PACs" }, "author": "ilyaigpetrov",