4 ms·
> 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-tim
by eigenspace 5y ago
> 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#issuecomment-766243445 https://github.com/JuliaLinearAlgebra/Octavian.jl/issues/24#...
- duped 5y agoDoesn't Julia use a mark-and-sweep GC? How is it possible to use in a soft-real-time context without stopping the world?
- eigenspace 5y agoJust 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 https://www.youtube.com/watch?v=dmWQtI3DFFo
- eigenspace 5y agoOkay, 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.
- cbkeller 5y agoHonestly 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).
- eigenspace 5y agoI think the lack of solid guarantees for optimizations is enough to downgrade it a little past "perfectly fine"
- duped 5y agoThat'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.