4,199 karma · joined December 10, 2014
I wonder if instead of using a boolean field in the Segment struct, better results might be attained by using a tagged union (enum in Rust-speak):
struct Point {
x: f64, y: f64
}
enum Segment {
Degenerate {
p1: Point,
},
Full {
p1: Point,
p2: Point,
p3: Point,
p4: Point,
}
}
impl Segment {
fn upgrade(&mut self,
p2: Point,
p3: Point,
p4: Point) {
match *self {
Segment::Degenerate { p1 } => {
*self = Segment::Full {
p1: p1,
p2: p2,
p3: p3,
p4: p4,
};
}
_ => ()
}
}
}
I wonder if you could also get away without using the has_first_segment variable by using the Vec::len method: if segments.len() > 0 {
segment_number += 1;
}
Of course, that's assuming the author doesn't find a better way to represent the pattern of accessing the previous, half-built segment. I suspect you could perhaps do so by creating a mutable partial Segment on the stack from an iterator's first element, and then actually looping over the remaining items in the iterator to actually construct segments, adding them to the Vec as you go.EDIT: It doesn't look like this thread is going anywhere, but I saw a comment on the Rust subreddit to use a Point struct which I quite liked, and incorporated here.
When doing very performance sensitive things in Rust, I usually find myself asking questions a lot on IRC and looking at disassembly in perf.
To answer some specific examples you cited above: I'm pretty sure that enums are (almost?) always equivalent to tagged unions. If you have an enum which doesn't contain any data, then I believe it's representation is just the tag. Iterators are just structs with methods, the various generic functions they implement are monomorphized and then optimized by LLVM.
Re: unsafe, I think that's tough. My personal feeling is that many of Rust's selling points rely on minimizing the use of unsafe (i.e. limiting segfault-relevant portions of the code), and that there are frequently ways to make things work and also make them fast without using unsafe. What's an example where you found yourself thinking about using unsafe instead of a more complex safe construct?
(Somewhat related to this, and especially for anyone reading who might try Rust, I cannot recommend getting on IRC strongly enough. The Rust IRC channels are by and large incredibly friendly and helpful, and for better or worse that's where a lot of the knowledge in the community is currently collected, not as much SO or blogs)
The conversation can be followed/joined/whatever here: https://github.com/rust-lang/rfcs/pull/1774
As far as I know, `#[no_mangle]` disables name-mangling but doesn't change the ABI of a function. That's what `extern "C"` is for in Rust -- to declare a function with the C ABI. You can have a Rust ABI function with an unmangled name (what it looks is done in the post) and you can have a C ABI function in Rust with a mangled name (by using `extern "C"` but not `#[no_mangle]` -- for example for C callbacks).
Based on my limited understanding of C++, `extern "c"` in C++ is equivalent to using both `#[no_mangle]` and `pub extern "C"` in Rust. I would guess that much of the time failing to specify a C ABI would work out fine unless you try to accept or pass non-FFI types (enums, references, etc) but I'm not sure.
It's confusing as hell. There was a thread about the mixed up semantics somewhat recently on the internals forum: https://internals.rust-lang.org/t/no-no-mangle/3973 (edit: and also https://internals.rust-lang.org/t/precise-semantics-of-no-ma...).
If you look at the LLVM IR generated from https://is.gd/Hfup3X you can see that the extern "C" fn differs in that it's given a `nounwind` attribute, among other things.
Is there a reason the Rust-exported functions aren't marked with `extern "C"`?
* https://github.com/nikomatsakis/rust-memory-model * http://plv.mpi-sws.org/rustbelt/ * https://kha.github.io/2016/07/22/formally-verifying-rusts-bi...
The first isn't using formal methods AFAIK, the second is, and the third is as well, but I think they're targeting safe code only.
Some discussion over on /r/rust: https://www.reddit.com/r/rust/comments/544hnk/ripgrep_is_fas...
EDIT: The machine I'm on is much less beefy than the benchmark machines, which means that the speed difference is quite noticeable for me.
fn main() {
println!("hello, world");
}
I kid, I kid. This looks cool!That said, there are many people who do quite well for themselves here, and they seem to love it. But it's not really a place where you can advance quickly by moving between companies. Most employees here seem to be lifers.
In terms of tech, there's not much to report. I got my current job through a personal recommendation, but was preparing to move away right before that happened. There are a couple of smaller tech companies, but otherwise developers pretty much work for the university, the hospital, W.L. Gore, Deckers Outdoor, or they work remotely (last year I met a principal architect from Blackboard who apparently lives here and works remotely for them). There are no meetups that I know of, and almost all of the jobs are .NET/JVM enterprise-y integrations and IT stuff. I'm sure there are little pockets that I'm not aware of, but there's only like 70k people who live here anyway.
So, uh, I guess my view of the economy is rather dim :). But that's not why one moves to this area -- it's the urban trail system, the backyard national forest, the easy access to the entire southwest, the low crime rates, the fresh air, the friendly people, the liberal mountain town vibe, the microbreweries, etc.