-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy loading #87
Merged
Merged
Lazy loading #87
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
remusao
force-pushed
the
lazy-loading
branch
2 times, most recently
from
January 15, 2019 14:06
1a5b4b2
to
ed42a77
Compare
Merged
This was referenced Jan 28, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a different, more compact representation for the engine. In a nutshell, it is now possible to load the serialized version of the Engine (as a typed array) and immediately start using it to match resources (with almost no loading cost). The required filters or resources will be loaded lazily and some will be cached in memory (e.g.: the small subset of filters which are needed on the visited domains).
Changelog:
provides a
serialize
method as well as a static methoddeserialize
.update
which expects a diff of filters,updateList
andupdateResources
. This API should be a cleared and allows using theadblocker without managing filters lists.
filters and instead expects a list of filters.
the filters classes directly instead of free functions. For example
NetworkFilter has a
parse
andmatch
method (with the same expectedarguments).
representation (stored in a typed array).
toString
method of filters should now be more accurate.All the benchmarks below are using one list: Easylist. Its raw size is 2.7 MB.
Loading time benchmarks
adblocker
with lazy loading in Chrome + Easylist loaded:adblocker
on master branch:Memory usage benchmarks
Some benchmarks on memory compared to before and other popular content blockers. These were performed using only
Easylist
loaded:adblocker
with lazy loading (this PR):Note: 1.3MB is used by
tldts
.adblocker
on master branch:uBlock Origin
AdblockPlus
[1] After browsing a few pages: spiegel.de, bild.de, lemonde.fr.
Synthetic benchmarks (Node.js)
These are the results in the test-suite running in Node.js:
adblocker
lazy loading:adblocker
on master branch:We observe that the time to initialize the engine from scratch (parsing the lists, etc.) is higher with the lazy loading. The performance is still reasonable though and this trade-off is fine:
We also see that the raw performance of matching requests is now ~3 times slower. This is hopefully a temporary trade-off and there are ways to re-gain the initial performance there as well (in a subsequent PR as this one is already quite massive).