runet-censorship-bypass/pac-performance-analyses/README.md
2015-12-21 02:04:34 +05:00

26 lines
1.1 KiB
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 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__.