
Show HN: Sauron – A web framework in Rust that adheres to the Elm architecture - ivanceras
https://github.com/ivanceras/sauron
======
twoquestions
Between 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!_

~~~
lostjohnny
Another 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)

~~~
jchw
I wonder how this copes with long-running pages. What happens if the server is
updated and the minimal update format changes?

~~~
jweir
I have no experience doing this, but Erlang and Elixir do support hot
upgrades.

 _The Big Elixir 2018 - Desmond Bowe - Hot Upgrade Are Not Scary_
[https://www.youtube.com/watch?v=IeUF48vSxwI](https://www.youtube.com/watch?v=IeUF48vSxwI)

------
donpdonp
From 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
"Lord of the Crates" doesn't quite have the same ring to it

~~~
Groxx
Cardinal of the Crates?

------
K0nserv
Sauron 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
You 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
Doh. 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-
fa...](https://hacks.mozilla.org/2018/01/making-webassembly-even-faster-
firefoxs-new-streaming-and-tiering-compiler/)

~~~
stjohnswarts
168k is nothing, that's less than an image by the standards of many web
elements these days.

~~~
structural
It's still a lot given that when targetting the entire world (especially
either mobile links or portions of the globe that don't have a CDN a
millisecond away), a typical assumed link is on the order of 512 kbps
bandwidth with 100ms RTT. That's two and a half seconds to load just your
framework with a cold cache and without including any content.

Yes, many web developers are just targeting their own areas and test on high-
speed links and everything seems fine, but frameworks that aim for widespread
use still need to care about every single byte.

~~~
paulddraper
jQuery is 84KB. react + react-dom is 109KB. Bootstrap 4 is 187KB.

Par for the course

------
frou_dh
Elm gets plundered repeatedly before it ever reaches version 1.0. Is name-
brand Elm still growing in adoption?

~~~
ivanceras
Because 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
Do 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.

------
leshow
How 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
Would it be fair to expect the performance to get better once the Web IDL
Bindings Proposal for WebAssembly is done?

~~~
leshow
If 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.

------
dbrgn
Obvious questions first: How does it compare to Yew?

~~~
ivanceras
1.) 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
Thanks, good luck with this project :) I'm looking forward to a mature Elm-
like web framework in Rust in the future.

------
holtalanm
Performance: Is not too bad.

I laughed at this, idk why.

~~~
ivanceras
I 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
yeah sorry. i meant that i laughed at it in a good way. i just found humor in
the way it was worded.

------
Octoth0rpe
Would 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
Since Rust supports macros, I think you can actually implement most of JSX's
syntax in it directly without needing an additional compiler.

~~~
steveklabnik
[https://crates.io/crates/typed-html](https://crates.io/crates/typed-html)

------
yumraj
(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
I 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.

------
bazza451
Commend 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

~~~
mattigames
Not 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
You 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.

------
owens99
Looks 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
Thanks. 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.

------
yuchi
Hey, interesting! Have you seen dodrio from mozilla? Could be a good candidate
for your diffing algorithm and improve performance a lot.

------
ksejka
Check out [http://blazor.net/](http://blazor.net/)

------
tiuPapa
So one thing, these are still slower and more expensive in performance,
compared to JS frameworks, right?

------
eljimmy
Slightly off topic - I can’t imagine calling the framework Sauron and posting
a photo from the LOTR movie is legal.

~~~
zbentley
I’m not an expert, but that seems like an example of fair use to me.

~~~
jerf
Is 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
The 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
That's for using the same word for different things. You can start a new
company called Apple in other industries, no problem. You can _not_ use the
Apple computer company's logo as yours, though.

You can probably use Sauron, but you can not literally put up a picture of the
Eye of Sauron as your project logo without making it appear that you are
operating specifically as that trademark holder. With that picture, they're
not just claiming to be "a" Sauron, they're implicitly claiming to be
associated with whoever currently holds the rights to those movies.

(I'm only hedging on the "probably" because of the known litigiousness of the
Tolkien estate. Normally it shouldn't be a problem.)

------
fxfan
I'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

~~~
raquo
What specifically are you waiting for? You can already run rust in the
browser, by compiling it to wasm and talking to the DOM using wasm-bindgen
(like this Sauron library is doing).

------
ryanmarsh
Folks 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
There 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
That's white supremacist thinking... /sarcasm

