4 ms·
I was wondering, given that 90% of the javascript in browsers must be standard libraries (jquery, bootstrap & co) wouldn't it make sense for google to hash the
by cm2187 9y ago
I was wondering, given that 90% of the javascript in browsers must be standard libraries (jquery, bootstrap & co) wouldn't it make sense for google to hash the source code for every published version of these libraries, compile those statically using full optimisation and ship the binaries as part of their updates to the browser, so that you only have to compile the idiosyncratic part of the code?
- sand500 9y agoMaybe ship popular libraries as web assembly?
- mhh__ 9y agoCould be done, although it would have to be done carefully.
- sjrd 9y agoRight, because wasm is there to solve all our performance problems, isn't it? And how exactly is your jquery.wasm going to access the DOM? Or expose methods to your application, for that matter? wasm is not a drop-in replacement for JS.
- Spivak 9y agoNo, but if we're being honest, it's exactly what everyone wants it to be. A bytecode for the web.
- Fifer82 9y agoI really don't know much about wasm. I just wondered though, from a birds eye view, does using wasm effectively give you control of everything within the "frame" of your browser? Can I get rid of the DOM(boilerplate aside), get rid of CSS? For example HTMLCanvasElement is a flat surface. I can do what I want within it as a scene graph renderer. Could I do that with wasm? Could I invent my own 2D entities (x, y, width, height). My own 2D Constraints resize like Apple Devices etc?
- skybrian 9y agoIt's still in the same sandbox as JavaScript. You don't get any new API's. There's only going to be speedup on CPU-intensive things.
- markdog12 9y agoThere are plans for WebAssembly modules to directly access the DOM: https://github.com/WebAssembly/gc/blob/master/proposals/gc/Overview.md#host-types https://github.com/WebAssembly/gc/blob/master/proposals/gc/O...
- adamnemecek 9y agoEventually the Dom might be replaced with some webgl renderer.
- flavio81 9y ago> wasm is not a drop-in replacement for JS It is not a "drop-in" replacement in any way, but I'm pretty sure it will eventually replace JS completely.
- ndesaulniers 9y agoNo, web assembly does not support dynamic typing that is used by many functions in these libraries. Dynamic typing may not be fast, but it is useful.
- chrisseaton 9y agoYou wouldn't be able to optimise the standard libraries very well without any information about the program calling them and the data they are using, though. I guess it would turn out to be a lot slower in practice.
- jFlatz 9y agoI feel like this is one of those things that I have been thinking to my self for a little while now. "Why hasn't someone already solved this problem." In my mind there is no reason for my browser to download 26 copies of the same jquerry file.
- ChrisSD 9y agoIf [websites] use a common CDN then this can be avoided. [edited, with thanks to delinka]
- delinka 9y agoIf the sites you're visiting use a common CDN then this can be avoided.
- tracker1 9y agoThis was going to be my comment as well.. I tend to prefer cdnjs for as much as possible, since it seems to be the most diverse CDN in terms of supported libraries. Though I've been trending away from using most libraries separately and bundling... may need to think about breaking things out again. For the most part, however, most of my bundle sizes are pretty small. React in dev, Preact for prod is the biggest mix... checking bundle size before/after adding a module (some will add a huge dependency tree). There's no substitution for being judicious... and imho, even if you have to look it up frequently, using the DOM is usually better than loading in jQuery... even if you center around Array.from(document.querySelectorAll('...')) as your main usage.
- cpeterso 9y agoHere is a proposal to use the hashes from <script> elements' Subresource Integrity attributes to cache JavaScript. There are some concerns about leaking users' browsing history based on resource load times. https://hillbrad.github.io/sri-addressable-caching/sri-addressable-caching.html https://hillbrad.github.io/sri-addressable-caching/sri-addre...
- slackingoff2017 9y agoIf ES6 used hashes to version libraries this might be possible. I still think you'd have too many versions to keep track of. In other spaces the pendulum is swinging away from shared libraries since storage space and bandwidth are relatively cheap. Java is often distributed as "fatjars" these days. IOS and Android apps bundle their dependencies the same way as far as I know. The whole serverless movement is a move away from shared code for better or worse.
- deleted 9y ago[deleted]
- erikpukinskis 9y agoAdding an entire new layer of complexity seems like a bad tradeoff. You'd break the debugger. You'd break the security model.
- colordrops 9y agoI'm thinking it's because they already have mounds of tech debt that would better address long term issues if they had the time to work on it. Take a look at the chromium bug tracker. It's overwhelming.
- fenomas 9y agoWhat are you suggesting "compile those statically using full optimization" would mean in this context? The point of the article is that v8's optimizations work by watching the code execute. It can inline functions because it saw where they got called from; it can turn property accesses into fixed-offset lookups because it saw what object the accesses happened to, and so on. (Unless you're talking about asm.js-style optimizations, but then the answer is presumably to use asm.js...)
- dfox 9y agoMost of what jQuery does could be moved into standard browser APIs and then presumably implemented in native code. I feel that implementing it that way would certainly be significantly faster, because any performance loss from impossibility of trace-directed optimizations is outweighted by significant reduction of amount of crossings between native and JS code with completely different memory model. The fact that VM/native transition is expensive is exactly the reason why things like WebAssembly cannot directly manipulate DOM. But this could not be implemented by writing C++ class that gets exported to JS code as $ when something that looks like jquery is loaded. In JS you can load jQuery and then monkey patch it, which will break when you use this kind of "transparent" optimization.
- robin_reala 9y agoMost of what jQuery does could be moved into standard browser APIs and then presumably implemented in native code. It pretty much has been. CSS syntax for selection lead to querySelectorAll, simpler AJAX calls to fetch, DOM manipulation functions were ported into the DOM spec wholesale.
- cm2187 9y agoI don't understand well enough dynamic language compilations to answer that but in principle, having 1 billion devices consuming CPU cycles to JIT recompile the same javascript paths over and over seems horribly wasteful.
- chrisseaton 9y ago
- pcwalton 9y agoThe fundamental problem is that interprocedural optimizations break that model. Optimizations that inline e.g. jQuery code into callers are very important. You end up needing to do optimization on jQuery either way. Additionally, the code that JavaScript JITs generate is not position independent, and it contains no linkage information (symbol tables, etc.). It contains raw addresses of various browser objects within it. You would need to introduce some sort of linker for that to work, which is a lot of complexity.
- flamedoge 9y agodoesn't mean it can't be done
- pcwalton 9y agoIt could be done, yes, but you'd have to weigh the benefits of caching against the performance downsides of linking and IR serialization. I wouldn't be surprised if it ends up not being worth it in practice.
- jbergens 9y agoThe js landscape changes really fast, they could probably never keep up.
- nitwit005 9y agoThe order of scripts matters, so it's not really possible except for the first script (similar to C/C++ #include optimizations). Even then, you'd have to deal with the possibility of someone modifying something the scripts create.
- ndesaulniers 9y agoSimply hashing these wont work since the scripts may be minified by different tools. Also, there's lots of different versions of these libraries, so we're talking about a fairly large number of precompiled libraries.
- Vinnl 9y agoDecentraleyes [1] does something like that, although it still fetches them from a common CDN. That said, I'm not sure how well it works: there are many, many different versions of every different library around, and when they're bundled, you don't get to see them separate anymore at all. [1] https://decentraleyes.org/ https://decentraleyes.org/