-
-
Notifications
You must be signed in to change notification settings - Fork 522
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
Combining JS CSS: 1. For developers 2. For performance: build script (can be optional for the extension to run) (Current folders aren't final either but complex /back form a thought of running on m.youtube or all HTMLMediaElements) #2415
Comments
👍 (and or we could meaningfully merge some again for everyone )
why?
(*it's not lost but causing an extra click) Originally posted by @ImprovedTube in #2391
stuff in later files relies on stuff declared in earlier ones. Not a problem if combined into one. Originally posted by @raszpl or, to make things able to wait for each other, it might not take too many lines of code? @raszpl i mean while easiest, it isn't fully intuitive to merge, when UI & JS often isn't just procedural already, if the loop could pre-load all at once & start each in the right nano second, given each requirement. (if that's right, then the remaining question could be just if many files will cause any significant IO considering the sum of all users, and the few whom might have old, full, worn storage that breaks tomorrow) Originally posted by @ImprovedTube
thats how it works now, synchronous waiting for all the files loaded one by one is slow and bad
?
in a build script when packaging for release. Source code can stay fragmented. Originally posted by @raszpl yes
, which isn't fully / permanently required. since (ideally) most can run at once, or else wait for a specic event Originally posted by @ImprovedTube
Can you show me a working implementation of this in the wild? Originally posted by @raszpl |
it's just general context: we don't know each & every of our code yet; many JS features (in a browser) can either run in parallel & we might want to draw & test our little dependency graph. (All of which doesn't directly relate to split files)
While splitting code in files can results in random reads costing ~0.1ms per file (or ~10ms for HDD), |
I mean its right there, you can just read it all in one-two sittings :-). Im at ~30% at this point by only reading stuff related to rewrites or bugs I go over.
Not necessarily buys us anything, or even makes stuff worse. Sure we can call everything inside ImprovedTube.ytElementsHandler asynchronously - this will give browser time to draw stuff it wants to draw first just to immediately trigger costly repaint. By changing elements as they are being added to html (by youtube.com /desktop_polymer.js) most(all) are changed in flight before first painted.
https://www.youtube.com/watch?v=y8OnoxKotPQ but yes, there are still horrible race conditions. Every time I see a workaround with setimeout its another problem :( Or that Firefox bug #2242 #2137 (comment) where autoplay was called before we grabbed player. There are still little gremlins like that hiding in the code, working only by chance and sheer luck.
higher load time so opposite effect, we actually need most of the stuff being loaded, gating it behind async load just shifts where the delay happens. Pushing more work to client side is always nonsense when choice is that or doing the work offline while packaging.
It looks like extension started with all the code in Isolated execution context, stuff that now lives in \js&css\extension\ , but later someone decided to keep piling more stuff injected directly into page (whats now in js&css\web-accessible).
doing more work, especially in js, is almost never faster
build script wouldnt remove anything, but compact it into one file making extension.inject one fast operation instead of synchronous chain. Another thing. Chrome supports World: MAIN. This:
Instantly automagically injects /web-accessible/ leaving \js&css\extension\init.js to flat out just call
and \js&css\extension\core.js:
TLDR no waiting for injection, just start running as soon as chrome.storage.local.get callback executes. Sadly as I mentioned somewhere else Firefox just implemented it 29 days ago, but afaik not shipped in 127.
more work refactoring everything
there is no CSS loaded event (thankfully!), its all handled by browser now.
browser does it much better internally
sound good in theory, but javascript routines rarely if ever can beat browser executing native code. All the themes take maybe 100KB of ram. The only problem with themes and CSS in general now is relying on attributes by value (CRIME!), those make CSS cpu heavy. Instead of
Thats what uBO is for :) plus most third party browsers started incorporating their own blockers in anticipation of MV3.
its not the fetching that is slow, its the javascript doing the fetching. Changing to asynchronous javascript wont make it any faster. webpack makes some sense ONLINE when instead of loading x-xxMB x.js file over wifi\mobile one can load thin shim and start executing something unrelated either while rest of that x-xxMB loads in the background, or sacrificing latency for async fetching on demand. https://tonsky.me/blog/js-bloat/ |
hi! @raszpl I should use structure before posting! (Just collecting any points doesn't mean taking any counter-position in a debate! & "webpack?" (several features) was to answer the question 😆 unrelated to the thread #2415) )
👍 this can be documentation for this project as long as it is like this! Timing:
( feel free please (https://github.com/search?q=repo%3Acode-charity%2Fyoutube+setTimeout&type=code), besides the one in autoplayDisable() ) Declarative programming & CSS:
*scroll to bottom at #2197
yes, i think checking value of CSS attribute will run a few times slower in millions of times per second than checking for classes. How many of each are we running per second yet?
Thanks for caring! Can be adjusted, while these feature's user count might increases
Rule syntax's equal a(/the browser-extension-)frame-work! (also to set JS variables such as YouTube flags.) Code in more than one file:
*(=in the given state it will be a minimal change to only load half the files depending what features are enabled or not. Said to be complete, even if that might remains slower to load at first and the code isn't split optimally for that.)
was added here along with a Manifest3 guide i think: it might helps to keep frequently called small files in the browser's in-memory cache (to check exactly)
still wanted to appreciate:
#2073 (comment)
(yes, just replace the file injection function) IO:more RAM! AND an IOP for opening that file 😀
is it? i like counting /speculating IOPS
(*..since for every change of settings of an extension, it might runs 100+ times without change. So hypothetically, if one could dynamically rewrite a single script, that could just have a single "big" read every time and a single "big" write for changes only.) |
Im not arguing as much as trying to share what I know :)
dont take my word for it, test test test and verify. Might be my computer or config after all. I just rechecked and this time init.js lands just after HEAD, so it might have been my bogged Browser session. But even after HEAD is too slow - YT JS files loaded in HEAD might have started running at this point.
Browser event loop is non intuitive https://developer.mozilla.org/en-US/docs/Web/JavaScript/Event_loop
I only understood that sentence today when rereading :D /slaps forehead/ You meant 'styles on body' which I so "creatively" mentioned later in my post :D
imo still need, better to have distinct private class names when injecting into foreign code, it- prefix nicely secures that
You can get some sense of the cost using devtools performance tab, CSS cost is there https://nolanlawson.com/2022/10/22/style-performance-and-concurrent-rendering/
its not the feature at fault here, afaik those * are not needed there, but their presence makes those CSS rules super heavy (compared to proper rule)
who decides which half? and how decides? :) and why decides when if can all load at once? The loading part is not slow, its the 'lets load one by one using js loop'
anything you do in js will be heavier/slower than letting browser just load it all and handle on its own, anything. JS is pretty fast , but its downright pathetic when compared to Browsers native code and internal optimizations.
Afaik themes absolutely NEED to be loaded by the browser and not injected by js to make sure they get applied as fast as possible avoiding annoying black/white flash before actual color applies. Whole extension when loaded takes 30MB of ram in Chrome/48MB in FF (about:processes), 100KB of Themes makes zero difference in comparison :)
then open devtools and look where
before HTML is even fetched from YT server, but our manually injected files are injected with huge delay. In Chrome all land after HEAD. In FF and Vivaldi first few somehow manage to squeeze just before HEAD.
From what I understand half the point (main is obviously killing uBO) of Manifest V3 is Google fighting with dynamic code execution |
hi @raszpl
Or an interesting thread: #2459(*developer-documentation; Firefox is Nr.1 soon. ) CSS
As long as css processing happens from right to left, https://github.com/search?q=repo%3Acode-charity%2Fyoutube+*%3D+language%3ACSS+path%3Ajs%26css%2Fextension%2F&type=code
(mainly background color)
Yes (at least in case of extension with similar but different features. And if we will offer to run some of this beyond youtube.com.) While replacing _ can be skipped if we write settings to at all. extension.inject
👍 Originally just meant to quickily agree in this topic & add that
|
(Assignments are not exclusive and mostly wishful) |
(from #2391)
Originally posted by @raszpl in #2391 (comment)
The text was updated successfully, but these errors were encountered: