10 ms·
Show HN: Sauron – A web framework in Rust that adheres to the Elm architecture
- dbrgn 7y agoObvious questions first: How does it compare to Yew?
- K0nserv 7y agoIt's based on Yew itself and since Yew is React/Elm like, but this is more Elm inspired I assume it compares like Elm vs React.
- dbrgn 7y agoAs far as I can tell by the Cargo.toml file, it's not based on Yew. The README mentions "This project is based on the existing projects: (...) Yew (...)", but I think the author meant "inspired by", not "based on".
- ivanceras 7y agoWhat I mean "based" is "I look at their code, and take only what I need".
- romanovcode 7y agohttps://github.com/ivanceras/sauron#performance-is-not-too-bad https://github.com/ivanceras/sauron#performance-is-not-too-b...
- ivanceras 7y ago1.) The syntax in creating the view: is just plain function calls which the rust compiler can accurately tell you about errors in your code, ie: typo, unclosed brackets/braces/parenthesis mismatch. 2.) Concise code, there is not too much ceremonial/boilerplate code to get started. 3.) Less code in the library maintain, there is no parser(which are mostly complex). 4.) Sauron is using wasm-bindgen, yew is using stdweb. 5.) It's in the early phase, so the performance is not yet optimized. https://github.com/ivanceras/todomvc-perf-comparison/ https://github.com/ivanceras/todomvc-perf-comparison/
- dbrgn 7y agoThanks, good luck with this project :) I'm looking forward to a mature Elm-like web framework in Rust in the future.
- kouteiheika 7y ago> 4.) Sauron is using wasm-bindgen, yew is using stdweb. FYI, since the most recent stdweb version it's possible to use `wasm-bindgen` with Yew
- eigenrick 7y agoNothing compares. Nothing compares to Yew.
- owens99 7y agoLooks cool, really like the name. It’s always interesting to me to see other developers who are good at branding, despite no obvious marketing background.
- ivanceras 7y agoThanks. I think I'm pretty good at naming. I have a few repo with good names as well. rustorm - an orm in rust diwata - a database UI in rust.
- Octoth0rpe 7y agoWould there be an easy/straightforward way to put a jsx transpiler in front of the rust compilation step, potentially with hot reloading? I realize that jsx in react is really just calls react.createElement, but I do think it's a very useful abstraction when you're ultimately constructing html.
- rimunroe 7y agoSince Rust supports macros, I think you can actually implement most of JSX's syntax in it directly without needing an additional compiler.
- steveklabnik 7y agohttps://crates.io/crates/typed-html https://crates.io/crates/typed-html
- mdtusz 7y agoLook into the framework Yew. It sits somewhere between elm and react in how it's designed, and makes use of an html macro that allows for jsx-like markup.
- rbalicki 7y agoThe main issue is that jsx can contain both mutable references to a variable and immutable references. For example <div onClick={() => count = count + 1}>{count}</div> contains both a mutable reference to count and an immutable reference. Thus, the naive way of storing this in a single struct will fail. The use of the elm architecture (where the onClick handler returns a message, instead of directly updating count) side steps the complicated borrow-checker issues. It is certainly possible to get around this with the proper procedural macro, but it is not easy, and will never be as "magic-free" as people want.
- frou_dh 7y agoElm gets plundered repeatedly before it ever reaches version 1.0. Is name-brand Elm still growing in adoption?
- ivanceras 7y agoBecause elm is elegant. I have written web-app with elm on the client side and rust in the backend. It was great, except for duplication of code when serializing/deserializing json data when making API calls. With sauron, I save up a lot of duplicated codes, and gotta squeeze that webassembly performance as well.
- asdkhadsj 7y agoDo you have any experience with Sauron vs Yew? I'm quite interested in Yew due to the benchmark and that their code examples look similar to me. Yew also says Elm inspired. Since I don't know anything about Elm, I'm curious to see what about Sauron makes it more Elm-y than Yew.
- Latty 7y agoThe main issue with Elm is the glacial development pace. I understand why it is the way it is (it shows in how well designed what is there is), but it really does hurt as someone who wants to adopt it.
- rickycook 7y agosome might say that’s a feature though!
- childintime 7y ago> Elm gets plundered repeatedly before it ever reaches version 1.0. I concur. Ever since Elm 0.17 [1], when Evan removed event streams and standardized on The Elm Architecture, Elm seems to have lost its way. Just saying as an interested outsider. [1] https://elm-lang.org/blog/farewell-to-frp https://elm-lang.org/blog/farewell-to-frp I presume it is a matter of perception: Elm is now perceived as a GUI toolkit rather than a language in its own right. Elm achieved simplicity and, ironically because of that, it is now plain easy to port its main ideas to other languages.
- bazza451 7y agoCommend on the attempt, foward thinking now wasm is getting more traction. but I can imagine that view syntax turning into an insane > circa the old days of callbacks in nodejs
- ivanceras 7y agoAs long as all event callbacks are delegated into the update function and unified in an Msg enum, the code will have the same pattern regardless of how big the project is.
- bazza451 7y agoDidn’t mean callbacks, meant shape of the code with indents could get large and difficult to grep. JSX style macro over the top might help .
- ivanceras 7y agoIn that case, breaking up the functions into several smaller functions helps. The rule of thumb of the size of a function body shouldn't be larger than the size of a computer screen.
- mattigames 7y agoNot convinced that's the case, with a bit of code splitting the view may end looking more like (pseudo-code): fn view(&self) -> Node<Msg> { div(self.attributes(), self.content()) } fn content(&self) -> Node<Msg> { input([ class("client"), r#type("button"), value("Click me!"), onclick(|_| {sauron::log("Button is clicked"); Msg::Click}) ],[],) }
- ivanceras 7y agoYou can also take a look at the window_tab_rows example. It will allow you to modularize into isolated subcomponents which you can embed into the main component.
- K0nserv 7y agoSauron looks really great and I for one am super excited about the future of Rust + WASM for web apps(with Backend). However I am a bit concerned that even the minimal example is 1.17MB of WASM which seems really high since Rust compiled to WASM should be quite small.
- ivanceras 7y agoYou need to use the script for release mode. $> wasm-pack build --target no-modules --release -- --features "wee_alloc" It will shrink it down to 165KB
- K0nserv 7y agoDoh. My bad for being a dummy. 165kb is still fairly big for a minimal example, much smaller than 1.17MB though, compared to React for example. Are there ways to analyze what contributes to the size for WASM compiled projects? I guess wasm-bindgen contributes significantly to the size currently. EDIT: It's 68KB gzipped and 165KB is the uncompressed size. One great benefit of WASM is that as described in "Making WebAssembly even faster: Firefox’s new streaming and tiering compiler"[0] it's much faster than JS to parse and execute. 0: https://hacks.mozilla.org/2018/01/making-webassembly-even-faster-firefoxs-new-streaming-and-tiering-compiler/ https://hacks.mozilla.org/2018/01/making-webassembly-even-fa...
- ivanceras 7y agoI think If you start adding more code, the growth of the release binary will diminish. The todomvc code is only 207KB when compiled and has relatively more code than the minimal example. There is a lot of rust compilation flags, and I have only tested a few. I also enabled a lot of wasm-bindgen features in the library, I will eventually tighten it up.
- wyldfire 7y ago> EDIT: It's 68KB gzipped and 165KB is the uncompressed size What's the state of brotli content type support in browsers? Wasn't that supposed to be the next generation beyond gzip? Would it get a better still compression ratio? And FB is pushing zstd -- is that something that might be supported eventually?
- eljimmy 7y agoSlightly off topic - I can’t imagine calling the framework Sauron and posting a photo from the LOTR movie is legal.
- zbentley 7y agoI’m not an expert, but that seems like an example of fair use to me.
- jerf 7y agoIs that the Internet's idea of "fair use" which is "I can pretty much do whatever I want as long as I say 'fair use'", or the legal one? Calling it Sauron is almost certainly OK. Using an image from the movie probably isn't, and the reason why isn't copyright, it's trademark. It makes it look like it may be officially related to the trademark owner. This may sound silly to you, but in a world where the New York Times has an active open source contribution page, along with other non-tech-companies that have put out open source like financial companies, audio companies, etc., the idea that a movie production company might put out a web framework is well within the bounds of possibility. For similar reasons, calling it Sauron is OK but I'd want to lean away from any obvious relationship to the Lord of the Rings, such as posting a satirical version of the ring's inscriptions. (A literary estate putting out a web framework is much less plausible, but on the other hand, they're well known to be on the litigious side, so personally I'd avoid it even so.) On the plus side, the worst case plausible scenario is a cease and desist, which may never come. Things only get nasty if the project refuses after that.
- xaqfox 7y agoThe granting of trademarks is narrower than that. The protection only applies to products and services that are "identical or 'colourfully' similar to the "registered" products or services". This is not to say that the holder would still not litigate out of fear of losing their mark, though.
- jerf 7y ago
- leshow 7y agoHow is Elm/Om doing so well in those benchmarks? I would think that most wasm frameworks would be able to blow past any js framework fairly easily. edit: Ah, calls to js are still necessary to create DOM elements, so there's lots of back and forth necessary in the wasm frameworks.
- pohl 7y agoWould it be fair to expect the performance to get better once the Web IDL Bindings Proposal for WebAssembly is done?
- leshow 7y agoIf my hypothesis is correct and it loses ground in benchmarks due to overhead of calling js dom methods, then I would expect native bindings to improve performance. I'm not an expert or anything in this field though, so maybe someone closer to the issue can chime in.
- steveklabnik 7y agoYes, that's why it's being pursued.
- holtalanm 7y agoPerformance: Is not too bad. I laughed at this, idk why.
- ivanceras 7y agoI traded a bit of performance for aesthetics by cloning the children of a node. I tried the todomvc benchmark and saw it wasn't so bad without employing optimizations in placed. It's still in it's early stage though.
- holtalanm 7y agoyeah sorry. i meant that i laughed at it in a good way. i just found humor in the way it was worded.
- gameswithgo 7y agoThe Rust community has high standards for perf!
- penagwin 7y agoThe usual mentality is "Use us 'cause we're faster than all those SLOW frameworks!" and then they show you a graph of a benchmark was in a specific instance they're X faster than the common options. It's fun to see some people being honest about it. "It's good enough" is pretty honest here.
- twoquestions 7y agoBetween this and Blazor ( http://blazor.net/ http://blazor.net/, among other wasm projects I'm forgetting right now), I'm glad more complicated UIs are being once again designed on the backend and keeping bundle sizes (relatively) small, rather than making everything in JS on the frontend and expecting everyone to download megabytes of code to visit a website. I'm looking in your direction Medium, at 6MB with a cold cache!
- gameswithgo 7y agoiirc WASM will tend to be larger than minified javascript.
- tracker1 7y agoIt depends on the JS and the WASM framework... Blazor in particular carries a lot of framework overhead with it. Also, like mentioned elsewhere in the article, something similar to JSX for one of these WASM frameworks would be very useful. As would a close to in the box UI toolkit that at least used or resembled material design or bootstrap.
- lostjohnny 7y agoAnother lightweight contender, not WASM though, is Phoenix Live View[1] [1] https://github.com/phoenixframework/phoenix_live_view https://github.com/phoenixframework/phoenix_live_view
- mrdoops 7y agoMy bet is LiveView will become the king of the fast prototype. It doesn't do SPA, but it does damn near everything else with ease and so few lines of code.
- jchw 7y agoI wonder how this copes with long-running pages. What happens if the server is updated and the minimal update format changes?
- ksejka 7y agoCheck out http://blazor.net/ http://blazor.net/
- donpdonp 7y agoFrom the README One crate to rule the DOM One crate to find the elements One crate to bring JSON And in the Rust code bind Strings
- antonvs 7y ago"Lord of the Crates" doesn't quite have the same ring to it
- Groxx 7y agoCardinal of the Crates?
- solidsnack9000 7y agoLord of the Strings
- yuchi 7y agoHey, interesting! Have you seen dodrio from mozilla? Could be a good candidate for your diffing algorithm and improve performance a lot.
- tiuPapa 7y agoSo one thing, these are still slower and more expensive in performance, compared to JS frameworks, right?
- deleted 7y ago[deleted]
- ryanmarsh 7y agoFolks please take care in how you name your open source project. Sauron is not something I want to think about every time I sit down to work, neither are cockroaches (CockroachDB).
- fxfan 7y agoThere was a time when people named stuff after positive things. If you asked my psychologist ex about people who name things after Saurons and Cockroaches, she'll jump to some 'priliminary conclusions'. This country needs frequent mental checkups like we have frequent dental checkups
- tracker1 7y agoThat's white supremacist thinking... /sarcasm
- vultour 7y agoDoes Sauron evoke some sort of primal disgust in you like cockroaches do?
- fxfan 7y agoI'm still waiting for something like scala.js for Rust. I don't like the thought of using two different programming languages and currently it seems scala.js is the most dependable front-end library
- yumraj 7y ago(Disclaimer: very limited knowledge about WASM) Curious as to how WASM impacts browser caching? In the JS scenario, several modules will be cached and change in one may still allow usage of other cached modules, thereby reducing future load times. How will that work in WASM work, since I'm assuming that the entire app will be packaged at build time as a single binary. Is the assumption even correct? Or, is it simply a question of architecting your app well into several WASM modules, since I'm assuming WASM modules (or whatever they are called) can call each other and do lazy loading.
- saagarjha 7y agoI can see this going in two ways: either we'll have WASM "shared libraries" that can be cached, or every website will go the way of apps and contain duplicate WASM modules in it.