13 ms·
Hello wasm-pack
- m_st 9y agoIt's great to see WASM taking off! In this context, see also Blazor, which runs C#/.NET code on WASM. https://github.com/aspnet/blazor https://github.com/aspnet/blazor
- steveklabnik 9y agoWhat’s the binary size like? One interesting thing about wasm is the difference between libraries and apps; Rust’s small binary size here can make it useful for this infrastructure work, but for languages that need to bring along the runtime, it’s much more complex. This is one reason why we’re pursuing stuff like wasm-pack. I’m glad to see more and more languages compiling to wasm though! Exciting times.
- wvenable 9y agoThe original Blazer was based on the DotNetAnywhere runtime and the binary size was actually very reasonable. Now that they're using the Mono runtime it's significantly larger and it seems their main task now is finding ways to remove unused code from that runtime to get it back to reasonable.
- deleted 9y ago[deleted]
- yougane 9y agoThe original runtime was about 60kb in size, that's still unreasonable to add to a library. Imagine a small library like Redux (2kb, including dependencies) having to ship with a runtime that's 60kb (or more). Now imagine a project that depends on multiple libraries of the same size or larger... This is why a language that has no runtime (such as Rust) makes more sense for developing wasm packages that can be used side-by-side with other languages.
- Dayshine 9y ago>The original runtime was about 60kb in size, that's still unreasonable to add to a library What? What kind of bubble are you working in?
- deleted 9y ago[deleted]
- yougane 9y agoWeb applications nowadays depend on hundreds of dependencies. If each one of these dependencies were to have a size of 60kb or more that would be very bad.
- coldtea 9y ago>The original runtime was about 60kb in size, that's still unreasonable to add to a library. In which planet? Not only will most frameworks and standard JS libs dwarf this, but the average web page size has upped to ~ 3MB these days...
- yougane 9y ago>Not only will most frameworks and standard JS libs dwarf this The original runtime that was used by Blazor was already a compact .NET runtime, and no matter how much you minify it (or any other runtime, such as the JVM), it will always have a considerable size. >the average web page size has upped to ~ 3MB these days... This is not an excuse to make web pages' sizes even larger :). Btw, I'm not against the idea of using a managed language that targets WebAssembly for front-end development. On the contrary, I'm very excited about Blazor and I'm following its development, and I would love to see similar frameworks for other languages such as Kotlin or Swift. But while I think the size of a runtime won't be an issue for web applications that use such frameworks, I don't like the idea of shipping large runtimes with wasm packages that might be used with other languages.
- wvenable 9y agoThere is an idea that the runtime could be hosted from a common CDN and then cached by the browser across applications so you only have to download the runtime once. Combined with browsers caching the compiled versions of the wasm modules, the cost of the large runtime might be pretty minimal in practice.
- kodablah 9y ago> What’s the binary size like? I asked this same question[0]. Appears mono.js is 166kb in release mode, but it downloads/uses the DLLs directly as a system would, so those sizes are the same as they are for desktop apps (not sure off the top of my head what that is for ASP.Net stuff or the stdlib). 0 - https://github.com/mono/mono/issues/7820 https://github.com/mono/mono/issues/7820
- steveklabnik 9y agoAh nice, thank you! The recent work with emscripten to get sizes down will help them too, I’m sure.
- kodablah 9y agoIt should be noted, I believe this is currently more of an interpreter than AOT-compiled like LLVM bitcode is. Mono is compiled via WASM that then interprets CIL DLLs.
- Mononokay 9y ago> As Lin Clark emphasizes in her article about Rust and WebAssembly: the goal of WebAssembly is not to replace JavaScript, but to be an awesome tool to use with JavaScript. Please no. JavaScript's a bit cancerous - we should be erring away from it rather than encouraging it.
- vijaybritto 9y agoYou are living in the past tbh. There are tools which make augment the language and it is literally taking over the world now!
- Mononokay 9y agoIt focuses on the lowest common denominator of programmers, and in general the community around it doesn't really care to optimize it or teach the people they attract towards good programming standards.
- lowtolerance 9y agoThis is simply not true. There are plenty of beginner-level JavaScript tutorials and resources out there, but the same could be said of any language. JavaScript libraries du jour like React and Angular are certainly not aimed at beginners, nor are popular tools of the trade such as Webpack and Babel. The focus is on allowing experienced developers to create production-ready web applications, which is exactly where it ought to be. I’ve been programming in JavaScript for nearly 15 years now, though, and there has been a near-constant push from the community toward better programming practices during that time. Given how far the language has come just in the past 5 years, I’d say they’ve been pretty successful in that regard.
- austincheney 9y agoJavaScript has a low barrier of entry, sure. That doesn't equate to the language being incompetent though. Every language has its incompetent developers. With Node.js you can perform some incredible systems automation cross-OS and it performs extremely efficiently.
- gramstrong 9y agoThis is great. Wasm really seems to be picking up steam. Any examples of a Rust crate that has already been published to the npm registry?
- steveklabnik 9y agoAshley and I ran a workshop at BoosterConf a monthish ago using this tooling, a bunch of people used it to publish demo packages. This is effectively a release announcement, so we don’t have anything super real yet that I know of. There’s some stuff in the works though. (You can see those here: https://www.npmjs.com/search?q=hello-wasm https://www.npmjs.com/search?q=hello-wasm)
- themihai 9y ago>> the goal of WebAssembly is not to replace JavaScript, but to be an awesome tool to use with JavaScript. Let's hope exactly the other way around will happen. I would rather like to see better interop between different languages using wasm than wasm + js.
- austincheney 9y agoI think that misses the point. Since WASM is a compile target you don't need JS to achieve interop between different languages if they are all compiled to WASM. The JS + WASM combo is to do things that WASM container cannot do on its own.
- fulafel 9y agoAlso, JS is a more suitable target for most managed languages like clojure, typescript, elm, etc.
- themihai 9y agoWell... two of 3 of the languages you provided as example were designed to be transpiled to javascript. I doubt JS is a more suitable target for other languages than an IR like wasm which is being designed to be a compiler target.
- fulafel 9y agoI would be interested in hearing a more detailed argument on why ClojureScript & Elm would be better if they targeted WebAssembly. Even the WebAssembly authors seem to agree that it's not foremost a managed language compile target - The Overview text from http://webassembly.org/ http://webassembly.org/ says "Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications."
- themihai 9y ago
- K0nserv 9y agoIt's been really exiciting to follow all the awesome work that Mozilla and the Rust team are doing in this area. I'm looking forward to this bright new Rust WASM future for sure!
- alex_duf 9y agoI'm dreaming of seeing a wasm DOM api that directly binds to the browser's apis, without passing through javascript. Is this even a possibility?
- grayrest 9y agoI believe that'd be a follow-up to the host bindings proposal [1]. [1] https://github.com/WebAssembly/host-bindings/blob/master/proposals/host-bindings/Overview.md https://github.com/WebAssembly/host-bindings/blob/master/pro...
- alex_duf 9y agoThanks for the link!
- steveklabnik 9y agoThat’s the “host bindings” proposal. All of this tooling has been written to be forward-compatible with it, so whenever that lands, you can upgrade the tool and get a speed boost for free.
- alex_duf 9y agoGreat!
- plurgid 9y agowhen we can make web pages, and entire sites without once actually using something a human can disassemble and reverse engineer ... this will be the end of the open web. truly the complete dead end of it. Unless maybe I'm missing something. Is a disassembler for WASM a thing yet?
- s73v3r_ 9y agoI cannot disagree more. Sure, the days of "View Source" might be coming to an end (although I doubt it), but there has never, and I mean never been an easier time to get started with these things. The vast amount of tools and resources for learning available for free is unprecedented. The open web is quite safe for years, if not decades to come.
- mpolichette 9y agoI cant help but think of the post about stealing password credentials from the site you build by surreptitiously inserting extra code into the published NPM package. Except wasm packages seem like they'd be even harder to detect. https://hackernoon.com/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8cb347c5b5 https://hackernoon.com/im-harvesting-credit-card-numbers-and...
- crispyporkbites 9y agoI have a package on NPM which is only partially implemented, using it in a production app is a bad idea, a quick glance at the source code or the todo section of the readme makes it pretty obvious. I still gets bug reports and npm says it has hundreds of download every month. For anything serious, read the source code, at the very least check your dependencies.
- ag_dubs 9y agofwiw as a former npm registry engineer i can tell u that "hundreds of download every month" likely is a result of the background bot activity npm gets. but your advice is sound! definitely vet your deps before you use them! and YES! read the source.
- probablycorey 9y agoIs this realistic though? Every time you update a dependency you would have to read its source (and its source dependencies, and their source dependencies...) To do that well, it would be someone's fulltime job to read and do security audits on all those dependencies.
- illustrioussuit 9y agoTheoretically, once something is updated all you would have to do is check the diff. Still tedious though.
- Y_Y 9y ago
- jnordwick 9y agoI'm kind of curious how wasm is going to work out. It seems only logical that wasm interpreters will be optimizing JITs. Wasm will essentially be an intermediate language similar to JVM bytecode. At that point why not just use the JVM stripped of the useless stuff as a base and add the remaining small pieces that might be needed. Or Graal. I guess I don't understand what Wasm is doing that is so much different that couldn't be handled with other more advanced code bases.
- kodablah 9y ago> It seems only logical that wasm interpreters will be optimizing JITs. Wasm will essentially be an intermediate language similar to JVM bytecode. Yup > why not just use the JVM stripped of the useless stuff as a base This often comes up in WASM discussions. First of all, you cannot divorce a JVM from its useless stuff. Many parts of the stdlib might as well be part of the bytecode (e.g. strings which then carries a done of charset code, classloaders, boxed primitives, method handles, lambda factories, etc). I would love to see an effort to leverage JVMs bytecode without all of it's baggage, but for now the marriage is so tight they are inseparable. > Or Graal That's a runtime VM/compiler, not a bytecode spec to target. > I guess I don't understand what Wasm is doing that is so much different that couldn't be handled with other more advanced code bases. Keep it simple, (mostly) no undefined behavior, no required GC, works the same on all platforms, large test suite, multiple big-company backers, etc. I can't think of an "assembly set" (or bytecode) that does all of that.
- Rusky 9y ago> It seems only logical that wasm interpreters will be optimizing JITs. Webassembly was designed not to do this, and I really hope it stays that way forever. Optimizing JITs are useful for highly dynamic languages like Javascript; Webassembly's fast startup times and predictable performance are a much better solution for languages like Rust. > I guess I don't understand what Wasm is doing that is so much different that couldn't be handled with other more advanced code bases. On top of "the vast majority of the optimization is done ahead of time so there's no need for a JIT," there's also the memory model. Webassembly exposes memory as a big array of bytes for you to manage yourself, just like hardware. The JVM enforces a particular object model with classes, inheritance, and garbage collection. So I guess what I'm saying is that "the JVM stripped of all the useless stuff" is what Webassembly is already. And some of the stuff that got stripped is the JIT and object model.
- ndarilek 9y agoDoes any of this tooling (I.e. wasm-pack, wasm-bindgen) work with the wasm32-unknown-emscripten target? All of the examples I see use wasm32-unknown-unknown, which is (I think) of limited use to me since I'm linking a fairly complex chain of native libraries against my current wasm target. It seems like cargo-web has lots of this ground covered already. I'm wondering why build these other tools in that case? I don't have a dog in this fight, I'm just working on a wasm-based app that I'm hoping will serve me for quite some time, and seeing what appears to be duplicated effort at such an early stage worries me a bit. Either way, thanks for building this!
- steveklabnik 9y agoWe’re focusing on the unknown target for basically all future work; this stuff can work with the emacripten target, but it might take some PRs to configure it, etc. We’d be open to people hacking on such a thing, but it’s not where the team is putting in any effort.
- ndarilek 9y agoGot it. I assume the unknown target will never be able to link against native libraries beyond those provided by Rust's core itself? I assume the answer is no, but a few years ago I assumed I wouldn't ever be able to do what wasm is letting me now, so I don't want to hold too tightly to those assumptions. :)
- steveklabnik 9y agoBy “native libraries” you mean “C libraries”? If so, then that’s correct, as rustc can’t compile C code. You need a C -> wasm compiler, and that’s emscripten. Hopefully we’ll have built the ecosystem enough that you won’t need to rely on those libraries :)
- mwcampbell 9y agoUnless I'm misunderstanding, this sounds like a mistake to me. On any other platform, Rust interoperates smoothly with C libraries and does not demand purity. There's lots of existing code written in C, and expecting all of it to be replaced with pure Rust libraries is unrealistic. Also, doesn't clang also have a wasm backend now? Emscripten isn't the only option.
- k__ 9y agoAre there any benchmarks comparing WASM with Neon on Node.js?
- steveklabnik 9y agoGenerally should be faster, it we haven’t made benchmarks. Lots of wasm is client side, Neon is server side. Wasm on the server is coming along too. It’s probably something worth putting together!
- k__ 9y agoah so it isnt in node yet?
- steveklabnik 9y agoIt is! It’s in the latest LTS even. But in my understanding, it hasn’t been a focus of node, and so sometimes stuff breaks, etc. It’ll get there! Certainly exciting as well.
- axefrog 9y agoDoes anyone have a good sense of the current performance impact of crossing the boundary between JS and WASM? I've often thought it'd be great to be able to expose high-performance data structures (and other infrastructure-level stuff) via WASM and then make use of them from JavaScript, but I seem to recall that the interop performance cost is currently too high to make it worth doing, which leaves WASM mainly only useful for long-running tasks, such as game engines, expensive graph layout algorithms and so forth. Edit: https://hacks.mozilla.org/2018/04/javascript-to-rust-and-back-again-a-wasm-bindgen-tale/ https://hacks.mozilla.org/2018/04/javascript-to-rust-and-bac... > "The wasm-bindgen code generation has been designed with the future host bindings proposal in mind from day 1. As soon as that’s a feature available in WebAssembly, we’ll be able to directly invoke imported functions without any of wasm-bindgen‘s JS shims. Furthermore, this will allow JS engines to aggressively optimize WebAssembly manipulating the DOM as invocations are well-typed and no longer need the argument validation checks that calls from JS need. At that point wasm-bindgen will not only make it easy to work with richer types like strings, but it will also provide best-in-class DOM manipulation performance."
- titzer 9y agoThe cost is more than a JS->JS call, but not drastically so. Every argument must be converted from a number to an int32/float32/float64, which for SMI values is a single branch, for heap numbers a branch and a load. For other JS values, a ValueOf() operation on the JS value. V8 generates little wrappers for these, with inline conversions. It does not currently inline the little wrapper functions, nor use ICs for the conversions inside, since branches are generally enough to get the interesting fast cases. The idea of a super-expensive call is therefore a bit of a myth. You can try to measure the cost yourself, but be careful! Most microbenchmarks will end up comparing the difference between an inlined JS call (as low as zero overhead) versus a non-inlined WASM->JS or JS->WASM call. The proper comparison would be instead with a non-inlined JS->JS call. Defeating inlining for JS->JS calls is tricky. You can do it with cross-realm calls, or by trying manipulating polymorphism. In either case, it's pretty tricky, so good luck.
- girvo 9y ago
- ridiculous_fish 9y agoIn its wasm-rewrite, the source-map module acquired a destructor that must be manually invoked by its clients [1]. This makes the API much worse. Is this typical of JS APIs that use wasm? 1: https://github.com/mozilla/source-map#sourcemapconsumerprototypedestroy https://github.com/mozilla/source-map#sourcemapconsumerproto...
- arcatek 9y agoYes, the gc isn't exposed yet, so neither JS nor wasm are notified when an object goes out of scope (which would allow to reclaim the memory on the wasm side). It's on the roadmap, so it should eventually come.
- deleted 9y ago[deleted]
- tschneidereit 9y agoThis is indeed a problem for Wasm/JS integration. The JS WeakRef proposal[1] will address it for many use cases, and the WebAssembly GC proposal[2], combined with JS Typed Objects[3] will address many others. Even before those features will be available, I'd expect the community to iterate on patterns to make APIs nicer. [1] https://github.com/tc39/proposal-weakrefs https://github.com/tc39/proposal-weakrefs [2] https://github.com/WebAssembly/meetings/blob/master/2018/presentations/2018-04-rossberg-gc.pdf https://github.com/WebAssembly/meetings/blob/master/2018/pre... [3] https://github.com/tschneidereit/typed-objects-explainer https://github.com/tschneidereit/typed-objects-explainer
- digi_owl 9y agoSo, yet another single purpose package manager. FFS...
- steveklabnik 9y agoThis isn’t a package manager. It’s tooling to create npm packages.
- chuckdries 9y agoCan you use JS packages as dependencies?
- steveklabnik 9y agoFrom the article: > The next large piece of development work on wasm-pack will focus on using custom segments in compiled WebAssembly to declare dependencies on local Javascript files or other npm packages. > The preliminary work for this feature has already landed in wasm-bindgen, so the next step will be integrating it into wasm-pack.
- jlebrech 9y ago"WebAssembly is not to replace JavaScript, but to be an awesome tool to use with JavaScript." NO, Replace Javascript, replace HTML, replace CSS.