Blog post: Rust vs Julia in scientific computing

I would make a similar argument about Julia Base. It’s frustratingly bare in some areas and quite difficult to add new functionality to it. With respect to Base.Threads.@threads, I have very low expectations of it.

This argument also applies to ThreadsX.jl and Tranducers.jl. The author, Takafumi Arakaki, @tkf, is a Postdoctoral Associate of the Julia Lab at MIT: Current members .

My suggestion is that if you are going to show “core” crates in Rust that you should compare to them to “core” packages in Julia. Admittedly, the concept of a “core” crate or package is a bit fuzzy.

There an important nuance here. Allocating uninitialized memory is not undefined behavior.

Here’s an example straight out of the Rust documentation. Note that it says this is not UB.

use std::mem::MaybeUninit;

// Create an explicitly uninitialized reference. The compiler knows that data inside
// a `MaybeUninit<T>` may be invalid, and hence this is not UB:
let mut x = MaybeUninit::<&i32>::uninit();

What is undefined behavior is attempting to read that memory before it has been initialized.

Zero initializing memory may not incur overhead in all circumstances, although Julia’s Base.zeros always does. One of my critiques of Julia is that zeros in Julia Base is implemented with an explicit memset rather than calloc. Depending on the operating system, libc implementation, and perhaps the amount of memory being allocated, calloc may not incur additional overhead because the OS or libc may already know that already zero initialized memory exists. New memory pages allocated to a process must be zeroed out as to not leak data from one process to another. I’ve elaborated on this in the discussion of ArrayAllocators.jl.

The history of the ArrayType{T}(undef, sz...) syntax may be of interest here. Basically, we wanted some indicator that something undefined was happening here. Some advocated for a shorter syntax such as ArrayType{T}(sz...), but it was felt that this did not sufficiently alert that user about what they were doing. The term undef was chosen over uninit or uninitialized. Essentially, the use of undef is meant to be regarded as similar to unsafe.

The performance recommendation you cite correctly uses this as it does initialize the memory before using it.

6 Likes