jspenguin2017 / uBlockProtector

An anti-adblock defuser for Nano Adblocker and uBlock Origin
GNU General Public License v3.0
740 stars 83 forks source link

[Discussion] For A Faster Future #249

Closed jspenguin2017 closed 7 years ago

jspenguin2017 commented 7 years ago
jspenguin2017 commented 7 years ago

Eh... What? http://jsben.ch/#/FKapz image ops spelled for wrong, ignore that

jspenguin2017 commented 7 years ago

Looks like V8 is not perfect, but as that can change, I will not make optimization that I think should be done by V8. It is faster now doesn't mean it will be faster later. However, jQuery and the DOM watcher are actual overhead and it's not V8's task to optimize them.

I might also fix let with loop, as the variable is “copied" every iteration and we don't want that. image

jspenguin2017 commented 7 years ago

let is substantially slower for loops... I think this is a problem on my end, since let does behave differently as per standard, I will fix it. image

jspenguin2017 commented 7 years ago

Normal usage: image After explicit garbage collection: image

DjDiabolik commented 7 years ago

I look this discussion... because it's suggested to use Violentmonkey and in the pass it's suggested Tampermonkeys ? What's the differences about this two script manager ? And because this combination it's only suggested to use all things on chrome and not on firefox ?

jspenguin2017 commented 7 years ago

@DjDiabolik Violentmonkey is open source. And it is significantly lighter than Tampermonkey.

I will do profile guided optimization for V8 JavaScript engine, but FireFox is using SpiderMonkey. The main reason I only support one browser is that I don't have that much time.

DjDiabolik commented 7 years ago

mmmmmm.... very interesting.... at this point you suggest to use Chrome because you don't have time to test if all it's working also in other browser ?

If yes i can say i currently use all setup on firefox and tampermonkeys and apparently all it's working whitout any issue or critical issue....

If you sugget violentmonkeys... violentmonkeys it's also released for firefox and i thinks i can tryed to disabled tampermonkeys and try to use this for about some days......

jspenguin2017 commented 7 years ago

@DjDiabolik What if it doesn't always work? I don't want to fix it.

DjDiabolik commented 7 years ago

Oh... the current version it's work on firefox... this future version i don't know and if not working i thinks i try to found an alternative for firefox.....

EDIT for the moment i can only confirm apparently all it's work on firefox.. and i have the 8.12 script and the filters added on ublock origin....

jspenguin2017 commented 7 years ago

@DjDiabolik Here is an alternative that you may want to check out: https://xuhaiyang1234.gitlab.io/AAK-Cont/

DjDiabolik commented 7 years ago

Lol i know this configuration (and i have used AAK on ABP up to about 2 weeks ago)....... i have tryed to setup that but for moment i prefer to use ublock protector ways. How i have already says.. apprently i don't find problems and all it's work whitout any problems :)

The next future.... i don't know :)

EDIT Only for purpose........... also for now... i have removed Tampermonkeys.......... pass to Violentmonkey on Firefox and i have re-add my usual script (Adsbypasser and 8.12 ublock protector).....

jspenguin2017 commented 7 years ago

@DjDiabolik I'm not going to stop you from using unsupported setup, but do not open issue before testing on the standard setup.

DjDiabolik commented 7 years ago

But i'm not here for ask support... i'm here only to know because you suggest a single solution and now i know because you can't have time to test all setup whit all different browser and script manager...

I also ever says.... for moment apparently on firefox + violentmonkeys and all currently setup all it's working. and now i know If i have problems whit this setup you can't be helped whit that........

jspenguin2017 commented 7 years ago

Extra: A fun challenge for you https://github.com/jspenguin2017/AdBlockChallenge#adblock-challenge

okiehsch commented 7 years ago

https://github.com/jspenguin2017/AdBlockChallenge#ublock-origin-bab-defuserjs-bypassing-nightmare-mode

jspenguin2017.github.io##script:inject(abort-on-property-write.js, Math.floor) :wink:

jspenguin2017 commented 7 years ago

@okiehsch Wow, what?! I cached a reference to the good Math...

okiehsch commented 7 years ago

Well, this will obviously never work in real world cases anyway ,because of site breakage, but your rules didn't mention that.

jspenguin2017 commented 7 years ago

I explicitly cached the reference to the good Math, somehow BlockAdBlock refuses to use it... Good job on it 👍 I'm not sure if it will cause breakage as I don't think many pages use Math.floor.

okiehsch commented 7 years ago

More than you think, I tried this fix with a few sites to circumvent different anti-adblock scripts, but it always lead to severe site breakage on my end.

jspenguin2017 commented 7 years ago

@okiehsch Anyway, it's fixed...

![image](https://cloud.githubusercontent.com/assets/7283682/26748250/3d95cbb8-47b9-11e7-9866-6c077e23aef6.png)
okiehsch commented 7 years ago

Can I use any script:inject that is part of uBO-resources?

jspenguin2017 commented 7 years ago

You can use custom ones as well.

okiehsch commented 7 years ago

No need. jspenguin2017.github.io##script:inject(setInterval-defuser.js, (), 1000)

jspenguin2017 commented 7 years ago

https://github.com/jspenguin2017/AdBlockChallenge/commit/4c0176b66f3980dfb8fe2d351d7b8fc6dae2b4f0

okiehsch commented 7 years ago

Well, Math.floor and setInterval. were the two obvious ways to circumvent and you clearly only forgot or overlooked setInterval. Now, I don't have a solution. Good job.

jspenguin2017 commented 7 years ago

Looks like if we want local i, either way is the same. image

jspenguin2017 commented 7 years ago

Switching to algorithm 2 😄 image

jspenguin2017 commented 7 years ago

WOW, new a.domInc is over two times faster! image

jspenguin2017 commented 7 years ago

Not a big improvement, but it's worth it. image

ghost commented 7 years ago

these "couple milliseconds faster" microbenchmarks are making me sick

i think you are doing your codebase a big misfavor by making non-obvious (confusing and less readable) and engine-specific (what if they're slower in other browsers?) micro-optimizations instead of going after what's actually slowing it down

inefficient code will be inefficient regardless of the language features used, and different loop styles and caching regexps are exactly the kind of pointless optimizations i hate

javascript should come with an instruction manual that has useful tips like "microbenchmarks aren't representative of real performance" and "simplifying and removing code and just doing less is the best optimization technique"

and something like "think about what the code does, not what the compiler does"

Also, I will be chasing the latest ECMAScript standard that Chrome stable supports

this makes no sense as new features are usually the least optimized ones, unlike older features that have had years of optimization work put towards them and have established coding patterns and conventions to actually optimize for

jspenguin2017 commented 7 years ago

@epicgirl1998 If I loop it more, it would be longer, it's not milliseconds, it's percentage. There are many complex code that I cannot remove, and I don't have enough tests to optimize what is actually slowing things down. Also, I don't care if it is slower in other browsers as I don't support them anyway. New features are less optimized but that will change. I won't try to use new features just because it's there though, I will always have a reason to use them, make the code shorter, simpler, or easier to edit later are good examples.

jspenguin2017 commented 7 years ago

@epicgirl1998 Also, I am thinking what the code does, it now compares integers instead of strings, which speeds it up significantly. I tested the loop structure because let would create a new variable for each iteration if the variable's reference is kept. But it looks like V8 is able to optimize it. I only tested things I think I am responsible for, I won't try to optimize things that I think it's V8's job to properly compile. And the code is not less readable, as I documented exactly what each function does. If you are just writing rules, all you need to know is what each function do and not how is each function implemented.

uBlock-user commented 7 years ago

these "couple milliseconds faster" microbenchmarks are making me sick

Then don't look at it instead of spewing a temper tantrum like this. Such small optimizations are making the codebase better and simplified with each update. Those milliseconds collectively can make a big difference when you measure the page load time, so nothing is insignificant here.

jspenguin2017 commented 7 years ago

Maybe having compilers written in C# was a mistake...

jspenguin2017 commented 7 years ago

Overview: image Compile: image Execution time including Violentmonkey wrapper: image Execution time of the Userscript: image Execution time of a.make$(): image

Most of the script execution time is used to load jQuery... I think I should lazy load jQuery...

jspenguin2017 commented 7 years ago

Compile time of minified script: change too tiny, and I would need a non-minified version for development, too little gain, and the gain doesn't apply to me, keeping as-is. image The execution time is still 49ms, no change there.

jspenguin2017 commented 7 years ago

Just realized that jQuery is used in generic solutions... Need to fix that first...

jspenguin2017 commented 7 years ago

OK, lazy loading is implemented... Hopefully I didn't break anything while refactoring the code... Here is the commit: https://github.com/jspenguin2017/uBlockProtector/commit/bcaaa3bf1c59f1a87a8952361635c2eacb9c229b

jspenguin2017 commented 7 years ago

One test left 😄

jspenguin2017 commented 7 years ago

split is significantly slower. Time to optimize the Core. image