News for hackers. Stuff that matters.
Re:Is Rust web yet? Not really by stcredzero on Wednesday May 28, 2014 @02:16PM (#7811885)
Not to be a curmudgeon but why would one want to use Rust for web development for a non-toy project?

I am a big fan of Rust, but as it aims to be a better C++, it is probably a better fit for OS development, game engines,

If there was an easy way of using Rust as a websocket server, I would be using that for my project instead of Go. The option to use reference counting is a Big Win when it comes to high degrees of parallelism on multicore processors. When you have GC, the GC thread comes along and causes cache misses for all of the other threads running on different processor sockets. With reference counting, garbage is "collected" locally.

Re:Is Rust web yet? Not really by drbawb on Thursday May 29, 2014 @11:23AM (#7816661)
I managed to get Rust wired up to websockets pretty easily.

There are working zeromq bindings: so you can use mongrel2 to handle websockets (with or without TLS) and then service those requests with a handler written in Rust!

You have to write the handshake & protocol framing yourself; but there's a reference implementation in Python[1] that's only ~200 lines long and supposedly passed the Autobahn test suite.

Rust's model of concurrency also jives really well with mongrel2's architecture.

---

There's one gotcha: receiving on a zeromq socket through the C bindings blocks the OS thread. This will cause your program to deadlock if you're using Rust's green threading. (Native "1:1" threading is the default however.)

[1]: https://github.com/zedshaw/mongrel2/tree/master/examples/ws

Re:Is Rust web yet? Not really by bfrog on Wednesday May 28, 2014 @04:02PM (#7812472)
Not everything is reference counted in Rust. Doing stack allocations in rust is actually really easy. Stack allocations in case your not aware are incredibly fast compared to anything else. The only thing faster is static allocations.

In Rust, from what I've seen, you basically have the option to avoid heap allocations almost entirely which is fantastic for performance. The only other languages that come close to giving you that ability in a very explicit and deterministic way that I know of are C and C++.

Re:Is Rust web yet? Not really by burntsushi on Wednesday May 28, 2014 @05:29PM (#7813091)
> In Rust, from what I've seen, you basically have the option to avoid heap allocations almost entirely which is fantastic for performance.

Not really. Any time you using a `Vec<T>` or a `String` type, you'll be heap allocating.

I suspect what you meant to say is that Rust does not force programmers to use some sort of garbage collection (whether it be reference counting or otherwise). That is indeed the case. I've written a fair amount of Rust code and haven't needed to use a GC at all.

Re:Is Rust web yet? Not really by pcwalton on Wednesday May 28, 2014 @08:22PM (#7813885)
> Not really. Any time you using a `Vec<T>` or a `String` type, you'll be heap allocating.

Well, we have the SmallVec type to avoid this if you can bound the size of your vectors. I would also like to introduce scratchpad allocators at some point, which should allow you to avoid heap allocations even for those.

Either way, there are many ways you can avoid heap allocations entirely. For example, my NES emulator does not call malloc() during gameplay, at all.

Re:Is Rust web yet? Not really by burntsushi on Wednesday May 28, 2014 @08:51PM (#7813974)
Oh cool, I didn't know about `SmallVector`! That's clever.

> Either way, there are many ways you can avoid heap allocations entirely. For example, my NES emulator does not call malloc() during gameplay, at all.

Definitely. Executing searches from `regex!` expressions won't heap allocate either. :-) (Sans the return value, but maybe that can be avoided too.)

Re:Is Rust web yet? Not really by stcredzero on Thursday May 29, 2014 @01:02PM (#7817238)
Doing stack allocations in rust is actually really easy. Stack allocations in case your not aware are incredibly fast compared to anything else. The only thing faster is static allocations.

This is also the key to programming performant Go. However, you can't really entirely avoid heap allocations, just minimize them.

Re:Is Rust web yet? Not really by fulafel on Wednesday May 28, 2014 @03:21PM (#7812233)
Ref counting is murder on caches. Every read will cause a rmw on the ref count cache line.

Modern generational GCs are reasonably nice on caches in most cases.

Re:Is Rust web yet? Not really by AlisdairO on Wednesday May 28, 2014 @05:01PM (#7812916)
This is not so much the case in rust because you only increment the reference count when you're passing around copied refs to an item. If you instead borrow a ref counted item, you don't need to increase the ref count - because rust will statically enforce that the borrow lasts less time than the item it borrows from (which is enough to keep the item alive). With good coding practices, you can eliminate the large majority of ref count increments/decrements.
Re:Is Rust web yet? Not really by yuriks on Wednesday May 28, 2014 @05:43PM (#7813159)
Such cache line will (because it is adjancent to the refcounted data) almost always be in cache anyway. Rust's refcounting is much cheaper than C++'s refcounting because it doesn't need to be atomic. (There is a separate type for atomic RC, and it is enforced by the compiler that you use it when needed.)
Re:Is Rust web yet? Not really by dllthomas on Wednesday May 28, 2014 @03:22PM (#7812236)
Every handoff, not every read, right? Of which there might be more or fewer.