15 ms·
Rustle: Svelte compiler rewritten in Rust
- n49o7 4y agoI've dreamt of this for ever.
- padolsey 4y agoCan someone explain what this is? Not much context and it's at the top of HN. Whoa.
- hardwaregeek 4y agoYeah this appears to be a repo with exactly one commit in it. Hopefully the author follows through and makes it but for now it's not really worth judging.
- ansible 4y agoDid you want more information on Svelte itself? https://svelte.dev/blog/svelte-3-rethinking-reactivity https://svelte.dev/blog/svelte-3-rethinking-reactivity
- JTBooth 4y agoSvelte is a frontend framework that isn't React, Angular, or Vue. This work is towards an installer that isn't Node. If you do frontend work and don't like React, Angular, Vue, and Node, this is all the things you like. (It's me, I dislike frontend frameworks and node and like svelte)
- zozbot234 4y agoIt's also a frontend framework that builds custom client-side JavaScript, which is where the "compiler" part comes in. This makes it way more efficient on the browser than the generic VDOM-diffing approach found in React, etc. Almost as quick as a static site, while preserving full interactivity.
- writteninrust 4y ago
- LoganDark 4y agoThis account should be a national treasure.
- kreco 4y agoYeah, it's close to an empty project. But since it's web-dev related and rust-dev related it deserves the front page on Hacker News...
- joeconway 4y agoSvelte and SvelteKit are absolutely worth playing with. It’s fun & refreshing. The svelte official tutorial is also nicely well made
- mhaberl 4y agoAfter some time spent with Angular/React I must say I enjoy using Svelte for building smaller apps. It is simple and fast.
- hegemon8 4y agoWhat about not-so-smaller apps?
- briantakita 4y agoI ported an Angular Universal app over to Svelte after one of the Angular major upgrades failed due to an Angular Universal bug that been around for years. Working with Svelte has been been great. I also like custom architecture since large apps will need custom architecture anyways. After porting the app over, it was easier to refactor the code without a heavy framework like Angular getting in the way. I also maintain a large app in SolidJS. I like SolidJS even more than Svelte, especially for large projects but also for small projects. Svelte has some disadvantages with tooling & some issues with Typescript integration. SolidJS allows more function decomposition & general flexibility in creating smaller more focused components, since the jsx/tsx components are plain old javascript functions. In addition, SolidJS javascript output is smaller than Svelte when the app hits a fairly low level of complexity. The engineering of SolidJS is more accessible than Svelte, so it's easier to understand what is going on.
- joeconway 4y agoThis is really interesting, thanks
- zozbot234 4y agoThat's what this project is for, ofc.
- orangepanda 4y ago> My main reason for doing this, is to compile Svelte without Node.js and possibly use Deno instead How does a rewrite in rust make using deno easier?
- norman784 4y agoMaybe because you don't need the Node.js runtime, so you can mix maybe Deno with Svelte?
- labrador 4y agoThe JavaScript engine in Deno has a Rust wrapper. Perhaps the Rust Svelte compiler can interact with the code in some beneficial way. Ryan Dahl - author of both Node and Deno (will the next version be "Done"?): One of Deno's strengths is Rust https://www.youtube.com/watch?v=ulJicGEeaYo https://www.youtube.com/watch?v=ulJicGEeaYo
- kandros 4y agoI think it means using rusty-v8 directly or it's API via Deno to SSR in deno runtimes or similar? https://deno.com/blog/roll-your-own-javascript-runtime https://deno.com/blog/roll-your-own-javascript-runtime
- labrador 4y agoThat's super nice looking Rust. You caused me to revise my opinion the Rust had ugly syntax. I got the impression when I wrote a file system tool in Rust a few years ago. I see things have improved.
- austinjp 4y ago> (will the next version be "Done"?) My vote would be for "Endo".
- crabmusket 4y agoI assume the plan would be to compile the Rust into a dylib and use Deno's FFI to run it? https://deno.land/manual/runtime/ffi_api https://deno.land/manual/runtime/ffi_api
- jokethrowaway 4y agoThis is a great idea but I don't understand why not to extend something like swc to support svelte. 95% should be already there (maybe this does that? https://github.com/wuyudi/svelte-swc https://github.com/wuyudi/svelte-swc)
- jraph 4y agoThe repository linked in your comment seems quite empty.
- austinjp 4y ago(Not OP) That repo looks like a proof-of-concept which is linked to from an open issue in https://github.com/swc-project/swc https://github.com/swc-project/swc which is apparently a "super-fast TypeScript / JavaScript compiler".
- mark_and_sweep 4y agoFor anyone excited about this project: The repo does not contain a compiler yet. It's just an intention to build one.
- discardable_dan 4y agoI really hope they don't follow the rustc 'OO' style of defining passes as traits. Pattern matching gives incredible tools for compiler pass writing, and the ideology of Rust compilers is ripe for being brought into the fold of OCAML-style compiler patterns.
- samwillis 4y agoAnd submitting a post to HN with the format “{something popular} rewritten in Rust” is always going to go straight to the top, even is they haven’t completed it yet, or maybe never will. The interesting thing here is really the reaction from the HN community, not the incomplete implementation. Having said that, this is a brilliant project.
- pjmlp 4y agoTo be fair, anyone that has been long enough in HN has seen the same with Ruby, CoffeScript, Erlang, Haskell, OCaml, Closure,... Eventually it pans out and gets replaced by something else.
- samwillis 4y agoQuite right, HN in incredibly susceptible to “fashionable” tech. Now that Zig has a significant VC backed flagship project, I suspect Zig will be the new Rust to HN. I would also add that rewriting something that exists in a new language is both a brilliant way to learn that language but also, if the language is still evolving, feed back improvements to the language itself.
- OtomotO 4y ago> Now that Zig has a significant VC backed flagship project What did I miss this time? Would you please elaborate?!
- erlend_sh 4y agoCame up on /r/rust two weeks ago and Svelte creator Rich Harris responded: > This project sounds awesome, and I'm sure we'll be able to learn a lot from it. Just a heads up that we will likely be making substantial changes to the compiler for Svelte 4, resulting in very different output JavaScript — thought I should mention that in case it affects your plans! https://www.reddit.com/r/rust/comments/wlmzx1/rewriting_the_svelte_compiler_in_rust/ https://www.reddit.com/r/rust/comments/wlmzx1/rewriting_the_...
- jraph 4y agoRich Harris seems so nice.
- deleted 4y ago[deleted]
- bigbluedots 4y agoDo we really need all of these "written in Rust" and "rewritten in Rust" posts? I know, it's a great language and everything but this is getting silly
- b4je7d7wb 4y agoIt would be an interesting post no matter what language. C, Go, haskel etc. That is if it was an actually working compiler.
- deleted 4y ago[deleted]
- spiderice 4y agoIt is so tiresome to read this comment on every post dealing with Rust. How is the language that the compiler is rewritten in not relevant? Should the title honestly be "Svelte compiler rewritten in a different language" so we can avoid using the word Rust?
- albertTJames 4y agoThe appeal to always go for the new and shiny JS framework is crazy. {#each 'SVELTE' as char, i}.. seriously ! Svelte is the biggest scam of all, reinventing the wheel all the way.
- jraph 4y agoSvelte does things in a fundamentally different way than existing frameworks. It is very lightweight, both in the code size sent to the user and in terms of runtime computation, entirely ditching the VDOM by doing more at compilation time, requiring less resources, less powerful devices for a better result (because less janky). It is also quite intuitive for the developer. I'd like to see it spread or at least these ideas adopted elsewhere. We need a lighter web and Svelte could be part of the answer to this. It's also not exactly new, from 2016. I hear you about the JS frontend framework and tooling churn, but Svelte actually brings something new and valuable.
- LoganDark 4y agoThe reason for all the hype around Svelte is exactly because it reinvents the wheel. (Rust also does this.) It proves that it's possible to create a web application framework that outperforms a Virtual DOM (VDOM), and does this by giving you one. Usually, you do minimal transpilation when you create, say, a React app - limited to converting JSX to React.createElement calls, plus bundling and tree shaking (if possible). That means all of the work needs to be done at runtime, and React needs to keep track of a VDOM, where any changes can be made at any time, and there needs to be generic runtime infrastructure in place to handle that (diffing and reconciliation). Additionally, each render completely reconstructs its slice of the VDOM, just to be diffed, leading to many wasted objects and CPU cycles even if nothing's changed. Svelte is a different approach which sees the inefficiency in that and tries to implement an alternative. Sure, it's "new and shiny" (even though it's been over 6 years since 1.0), but it has some real benefits! Svelte works by rewriting your code to make changes directly to the DOM, rather than going through a VDOM, and it does this by keeping track of all the possible changes at compile-time (along with things like event listeners and reactive state and so on) and hard-coding them in. So instead of getting a generic runtime framework that has to run everything through a VDOM, you get something a bit more similar to what you would have if you wrote the whole thing by hand using vanilla JS with no framework at all. Svelte has an article on the subject - I'd recommend checking it out: https://svelte.dev/blog/virtual-dom-is-pure-overhead https://svelte.dev/blog/virtual-dom-is-pure-overhead (Although I do think it's fad-like that Svelte is plastering their site with protest messages, that doesn't mean the technology isn't impressive!)
- jraph 4y agoBeing able to use Svelte without having to mess with NPM packages would be neat. (If it does not require pulling 1GB of Rust dependencies including the Rust compiler of course.) A Svelte compiler in Rust might be a very interesting code base to work on / to study.
- LoganDark 4y agoI believe rustc and all its dependencies are only around 500M on my machine. Not tiny, but not the 2GB that GHC requires.
- GolDDranks 4y agoI wouldn't expect this to need any of the Rust build chain, as Rust is a compiled language, just deploy the binary and you're done.
- pushkine 4y ago> Being able to use Svelte without having to mess with NPM packages would be neat. WYM? Svelte does not have dependencies https://www.npmjs.com/package/svelte https://www.npmjs.com/package/svelte
- LoganDark 4y agoI, for one, would love to see this come to fruition one day. Tools like esbuild have proven that front-end tooling does not need to be written in JavaScript, and seeing a Svelte compiler in Rust of all languages means that there could be some real innovation coming to this space. Definitely starring.
- cercatrova 4y agoRust (and other fast, compiled languages) is the future of Javascript infrastructure [0]. Whereas before one might have thought that a language's tooling should be written in said language, there might come a time when that's too slow, and we instead need to move to faster languages. That's what has happened to Python (numpy, pandas, scipy etc are all written in C and simply provide an interface in Python), and now it's happening to Javascript as well, with Deno, swc in Rust, Bun in Zig, esbuild in Go, and so on. I foresee a future where we won't have to deal with slow tooling and can have instantaneous updates once again. [0] https://leerob.io/blog/rust https://leerob.io/blog/rust
- jpgvm 4y agoEventually you realise this split sucks though. it creates a world where programmers of the higher level language can't reasonably debug their most important libraries. This is different from not being able to debug the runtime, which has a smaller API surface than important libraries and frameworks generally have (though I guess it depends on if you count stdlib etc sometimes). It's generally much better to simply go to a language that still operates at the same or similar level of abstraction but with higher performance. i.e going from Typescript to Kotlin isn't a substantial move from an abstraction level perspective but you no longer consider needing to write the code in C because it's not fast enough. (you might for other reasons, like runtime portability)
- cercatrova 4y agoHow does that work if end users want to use JS though? They're not all going to move to Kotlin. Since one must meet people where they are, rather than where we want them to be, the best we can do is instead have the end user still program in whatever language they want but then translate that into a higher performance language. That's basically what Python is doing now. Users don't want to write C/C++, they want to use Python, but Python is too slow, so here we are.
- jakobnissen 4y agoWhat you're describing is known as the "two language problem". The long-term solution is to move to fast, high-level languages. I think Julia and LuaJIT are the only examples currently, but surely more will crop up. This is s fundamental problem that will not go away on its own. Efforts like Numba can alleviate some of the pain of a slow Python, but it turns out it's generally not possible to retroactively fit a JIT compiler onto a language designed not designed to be compiled. In my experience, once I tried moving my work code to Julia, it became clear to me just how much energy I had spent trying to overcome the performance wall of Python, and I can't imagine going back now.
- thr0wawayf00 4y agoThis project isn't even close to being functional and yet it already has 750+ stars on Github. I guess that's one way to test the market for a project idea.
- hiccuphippo 4y agoHow many of those stars are from people who use Rust and don't use Svelte?
- T3RMINATED 4y ago
- deleted 4y ago[deleted]
- rayiner 4y agoVery impressed with the momentum around Rust. Interesting that Netscape/Mozilla has given us two widely used languages, at opposite ends of the spectrum in pretty much every respect.