News for hackers. Stuff that matters.
Re:From Julia to Rust by eigenspace on Saturday June 05, 2021 @08:01PM (#27409455)
> The biggest reason is because some function of the high level language is incompatible with the application domain. Like garbage collection in hot or real-time code or proprietary compilers for processors. Julia does not solve these problems.

The presence of garbage collection in julia is not a problem at all for hot, high performance code. There's nothing stopping you from manually managing your memory in julia.

The easiest way would be to just preallocate your buffers and hold onto them so they don't get collected. Octavian.jl is a BLAS library written in julia that's faster than OpenBLAS and MKL for small matrices and saturates to the same speed for very large matrices [1]. These are some of the hottest loops possible!

For true, hard-real time, yes julia is not a good choice but it's perfectly fine for soft realtime.

[1] https://github.com/JuliaLinearAlgebra/Octavian.jl/issues/24#...

Re:From Julia to Rust by duped on Saturday June 05, 2021 @08:17PM (#27409543)
Doesn't Julia use a mark-and-sweep GC? How is it possible to use in a soft-real-time context without stopping the world?
Re:From Julia to Rust by eigenspace on Saturday June 05, 2021 @08:43PM (#27409659)
Just because a GC exists doesn't mean you have to use it though. It's just another tool on your belt.

There's various options depending on your problem. You could just hold firmly onto memory, preallocating all your buffers before the program starts and then don't allow them to be GC'd, you could also use stack allocated arrays like in StrideArrays.jl / StaticArrays.jl, or some combination of the above. You could also just manually use ccall to malloc and free memory as needed I guess.

There's a nice talk here [1] about using julia in soft-real-time for robotics.

I'd say the biggest impediment to real-time programming in julia currently is not the GC, but instead that the language has lots of optional optimizations that the compiler can choose to not perform if it thinks it'd be beneficial to do so, and those optimizations can change between minor versions. Hence, there's a lot of testing you'd need to do to make sure your code really is doing exactly what you want and you won't hit the GC or dynamic dispatch, and you'll need to redo that testing every time you update julia or any packages, which is obviously not ideal.

[1] https://www.youtube.com/watch?v=dmWQtI3DFFo

Re:From Julia to Rust by duped on Sunday June 06, 2021 @09:16AM (#27412949)
That's not strictly true - if the GC requires all threads to pause ("stop the world") then there is no effective way to write code that isn't impacted without adding the soft real-time requirement and workarounds to every part of the program.

Essentially most GCs require you to pay for it even if you don't use it in critical sections. I'm not sure if Julia has the semantics for explicitly disabling GC during hot loops, but it is extremely difficult to do that without the dedicate hooks.

The issue is not performance - GCs are usually faster than not. It's determinism.

Re:From Julia to Rust by cbkeller on Sunday June 06, 2021 @12:08PM (#27414058)
You can just turn off the GC with `Base.GC.enable(false)`
Re:From Julia to Rust by duped on Sunday June 06, 2021 @04:56PM (#27416247)
does that disable it globally or just in critical sections?
Re:From Julia to Rust by eigenspace on Sunday June 06, 2021 @05:46PM (#27416642)
Globally. Is your concern about running latency insensitive code concurrently with running latency sensitive code?

For that, I'd probably just do multiprocessing and have one realtime process that only operates on preallocated or stack allocated buffers with the GC disabled, and then another separate process that does your latency insensitive stuff.

I'm sure other languages are able to handle this sort of thing more elegantly in one process with tasks, but it can be made to work in julia, and there are lots of situations like robotics where you may want to leverage Julia's excellent ecosystem in a realtime system, so I just disagree with your earlier statement about julia being incompatible with the application domain, even if it's not a perfect language for it.

Re:From Julia to Rust by eigenspace on Saturday June 05, 2021 @08:46PM (#27409679)
Okay, reading my earlier comment I said "perfectly find for soft realtime", that's maybe a bit too far. Let's go with "okay for soft realtime" instead.
Re:From Julia to Rust by cbkeller on Sunday June 06, 2021 @09:39PM (#27418092)
Honestly you were probably fine the first time, given that you can easily disable the GC, and that it's really not that hard to entirely avoid generating garbage (in which case the GC generally wouldn't have been triggered even if you'd left it on).
Re:From Julia to Rust by eigenspace on Sunday June 06, 2021 @11:00PM (#27418551)
I think the lack of solid guarantees for optimizations is enough to downgrade it a little past "perfectly fine"