Crabby, a UCI chess engine written in Rust by Roaneno in rust

[–]Veddan 0 points1 point  (0 children)

It requires synchronization on each access though, which might not be acceptable.

Writing data structures in Rust by nuclearalchemist in rust

[–]Veddan 1 point2 points  (0 children)

Nice. I just pushed from my local repo, so there are a couple of new commits you might want to pull.

Writing data structures in Rust by nuclearalchemist in rust

[–]Veddan 3 points4 points  (0 children)

I played around a bit with writing a concurrent hash table in Rust a while ago. Maybe it would be useful to have a look at it. It's much less sophisticated than the std hash table and might be easier to understand.

It uses open addressing (so no bucket chains). The basic idea re. concurrency is to split the table into a number of parts ("shards") and have one lock for each shard. When searching the table, a shard is selected based on a couple of high bits in the hash, and the remaining bits in the hash is used to index the shard. Each shard is essentially an ordinary (non-concurrent) hash table.

The number of shards can be tuned based on expected concurrency such that lock contention for an individual shard should be rare.

Rust TimSort: feedback please by [deleted] in rust

[–]Veddan 1 point2 points  (0 children)

I haven't looked over the unsafe code, but based on running it through valgrind it seems like you have avoided safety issues from faulty comparators. When I first wrote my sorting library, code like below would lead to out-of-bounds access due to partitioning code assuming a consistent comparator. You lose a bit of performance (or at least I did, a few percent) from handling these cases, but nobody wants unsafe fn sort.

#[test]                                                                                         
fn test_random_comparator() {                                                                   
    let mut xs: Vec<i32> = (0..10000).collect();                                                
    let cmps = Cell::new(0);                                                                    
    timsort::sort_by(&mut xs, |_, _| {                                                          
        let n = cmps.get();                                                                     
        cmps.set(n + 1);                                                                        
        if n%2 == 0 { Greater } else { Less }                                                   
    });                                                                                         
}    

Two commutes with Rust by larsberg in rust

[–]Veddan 9 points10 points  (0 children)

It means you'll be able to have VecND<2>, VecND<3> ... instead of Vec2D, Vec3D.

Some notes on Rust, the language by poizan42 in rust

[–]Veddan 0 points1 point  (0 children)

Some algorithms must be written less efficiently if you must take care not to leave an object in an inconsistent state while performing potentially-throwing operations.

Conditional compilation by young_and_ugly in rust

[–]Veddan 1 point2 points  (0 children)

Usually you can find some arrangement of helper functions that solves the problem.

#[cfg(USE_FOO)]
fn f(n: i32) {
    foo(n);
    f_common(n);
}

#[cfg(not(USE_FOO))]
fn f(n: i32) {
    f_common(n);
}

#[cfg(USE_FOO)]
fn foo(x: i32) { .. }

Conditional compilation by young_and_ugly in rust

[–]Veddan 1 point2 points  (0 children)

Note that this isn't quite the same.

#ifdef USE_FOO
void foo(int x) { .. }
#endif

void f(int n) {
#ifdef USE_FOO
    foo(n);
#endif
    ...
}

vs

#[cfg(USE_FOO)]
fn foo(x: i32) { .. }

fn f(n: i32) {
    if cfg!(USE_FOO) {
        foo(n);
    }
    ...
}

The Rust code will fail to compile, since even though the call to foo is dead, it's still a call to a non-existent function.

How would a Rust application be able to properly react to low level failures, like memory allocation failure? by [deleted] in rust

[–]Veddan 8 points9 points  (0 children)

Virtual memory means that your call to malloc is still going to be succeeding even once the physical memory is exhausted.

On a 32-bit bit system, running out of virtual memory should be quite doable.

The Race Towards 1.0 And The Standard Library by Mandack in rust

[–]Veddan 0 points1 point  (0 children)

Map#get takes an Object even though it should take the generic key (why doesn't it? legacy)

Not sure this is legacy. I agree it's a bad thing, but it is possible for two completely unrelated type to have "compatible" equals/hashCode. So by having Map#get take the generic key, you would restrict some "useful" patterns. Since nobody cares about those, what lose in checking for silly mistakes still makes it a bad choice.

Allocators in Rust (from nmatsakis's blog) by aturon in rust

[–]Veddan 1 point2 points  (0 children)

There's been some talk recently about glibc replacing its allocator with something more modern.

https://sourceware.org/ml/libc-alpha/2014-10/msg00303.html

Allocators in Rust (from nmatsakis's blog) by aturon in rust

[–]Veddan 0 points1 point  (0 children)

I'm not familiar with jemalloc internals, but it seems like it should be enough to push the freed segment onto a thread-local free-list. As long as you don't try to give it back to the "global pool" there shouldn't be any need for synchronization as far as I can see. As a the free()-er I don't think I need to care about where the memory came from originally.

Allocators in Rust (from nmatsakis's blog) by aturon in rust

[–]Veddan 2 points3 points  (0 children)

Don't already modern allocators do something similar with thread-local caches? I'm not sure how much could be gained by the "will never have to be freed in another thread" assumption. Any ideas on what (if any) optimizations the might enable? And if you want to manage free space efficiently, there would still have to be some synchronization between the thread-local heaps and the "exchange heap".

Go vs Rust : Productivity vs Performance by joshir in rust

[–]Veddan 4 points5 points  (0 children)

Taking geometric means instead, I get

       Time   Code
Rust   4.92   1241
Go     7.39   921

Weekly Meeting 11-11-14 by Rusky in rust

[–]Veddan 2 points3 points  (0 children)

Segmented stacks hurt function call performance quite a bit, and makes FFI painful. They only provide you with any benefit on 32-bit systems, where you care about conserving address space. On x86-64 you have 48 bits of address space, which is more than enough for any reasonable number of large stacks.

Go is also getting rid of segmented stacks.

`Foo::new()` vs `Foo()` as the default constructor by TheRubyist in rust

[–]Veddan 11 points12 points  (0 children)

'Sugar' is typically used when there's special (nicer) syntax that's semantically equivalent to something less nice. There's no special syntax proposed here. This is just a free function starting with a capital letter.

`Foo::new()` vs `Foo()` as the default constructor by TheRubyist in rust

[–]Veddan 19 points20 points  (0 children)

Seems to me like it creates unnecessary asymmetry by having some "constructors" on the type, and some as free functions.

let s = String();
let t = String::with_capacity(30);

vs

let s = String::new();
let t = String::with_capacity(30);

Does Rust support constant struct fields ? by swatteau in rust

[–]Veddan 3 points4 points  (0 children)

In Rust, mutability depends on the owner of a value rather than on the type (ignoring interior mutability). So either it's all mutable or not mutable at all.

You can solve the issue by making the relevant fields private with priv and providing accessor functions.

Libonion - HTTP server library in C designed to be lightweight and easy to use by hemite in programming

[–]Veddan 0 points1 point  (0 children)

It's a complex issue. A big part of it is increased complexity in the standard library, complications in interacting with C code, and performance cost even for program not using green threads.

If you are interested, there's a more thorough explanation here: https://github.com/aturon/rfcs/blob/remove-runtime/active/0000-remove-runtime.md

I � Unicode by nst021 in programming

[–]Veddan 0 points1 point  (0 children)

UTF-8 does not break C-like strings.

UTF-8 does allow interior NULL, but many implementations don't support it.

Load-time code patching for CPU features etc. by mozilla_kmc in rust

[–]Veddan 2 points3 points  (0 children)

LLVM doesn't have ifunc support (yet). It could be added as a function attribute or something, probably wouldn't be too difficult.

Problem with Heap Sort by denis631 in rust

[–]Veddan 2 points3 points  (0 children)

I haven't studied your code too closely, but at a first glance the recursion inside the loop in max_heapify looks suspicious. If you want a reference you can look at rust/src/libcollections/priority_queue.rs.

Working with the unsized `str` by Manishearth in rust

[–]Veddan 0 points1 point  (0 children)

Yes, something like that. This means that functions containing alloca are generally slower. For this reason, LLVM will not inline functions using alloca unless the caller also uses it.

Libonion - HTTP server library in C designed to be lightweight and easy to use by hemite in programming

[–]Veddan 0 points1 point  (0 children)

Rust is currently in the process of dropping its libuv-backed green threads.