Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm confused about the state of threading in Crystal. See the last message in : https://github.com/crystal-lang/crystal/issues/1967#issuecom...

I'm hoping to see more languages with light-weight threads automatically mapped (multiplexed) to physical threads, like in Go. So far, based on the crowd-sourced table I started working on, it is otherwise only Ada, Haskell and Pony (in addition to Go) that seems to meet these criteria:

https://docs.google.com/spreadsheets/d/1BAiJR026ih1U8HoRw__n...



Crystal will eventually have go-style parallelism as well as go-style concurrency. It's a hard thing to implement, and we don't have the resources of google (in fact we have very little resources at all) so it's taking time. Until 3 weeks ago, nobody at all was working full-time on crystal, it was entirely a spare-time project, so progress is slow, i'm incredibly proud of what we've managed to achieve so far and looking forward to more in the future.

Really, the best way to help the language is to donate: https://salt.bountysource.com/teams/crystal-lang


Great to hear, thanks for the info!


Java and .NET do that as well.

On Java's case it is up to the JVM implementors to decide, the spec does not impose OS threads. Hence why you can find the terms green and red threads on old Java related docs.

Then both support tasks which get multiplexed into the underlying runtime threads.


AFAIK you can add Nim to your list too. The Nim threadpool module[1] allows you to spawn M lightweight threads onto N kernel threads.

1 - https://nim-lang.org/docs/threadpool.html


Which, I'd like to say, is extremely easy to use in production, and actually quite easy to marry with the built-in kqueue/inotify/etc. event loop async/await!


Did you look at Erlang/Elixir?


Erlang isn't in the same category as the languages being discussed here. It's great for long running parallel tasks, but is slow af.


This shouldn’t be downvoted. I love Erlang, but it’s the latency that’s really fast (that is, low), not the throughput[0].

It just so happens that Erlang is frequently used as a network server and can probably saturate the network interface, so its throughput is usually judged to be Good Enough, while the latency is generating the positive headlines.

[0] There are exceptions to everything. If your problem allows you to write code in such a way that the critical path stays mostly inside the VM’s C code, rather than having to keep fetching your instructions, the throughput can impress.


And that's why he's being downvoted... Generically claiming that a language is "slow af" will mean different things to different people. Hence the interpretations. Hence the downvotes.


The parent of the post I replied to was about Haskell, Ada, Pony and Go. And the thread is about Crystal (with lots of mentions for Nim).

All of those share one thing in common, something which Erlang doesn't have in common with them.


Erlang absolutely does have this 'in common', and it makes this faculty known every time you start up the Erlang REPL.

In fact, I think there's a case to be made that it may have the most refined implementation for scheduling M:N processes (along with more advanced thread affinity, alternative RQ dispatching, SMP awareness, etc).


Was referring to the fact they're all languages which compile to native executables.


Well you’re either confused or being purposefully ingenuous. The original poster, samuell, said nothing about languages which compile to native executables, he said he’s looking for “languages with light-weight threads automatically mapped (multiplexed) to physical threads, like in Go”. Hence the suggestion of Erlang, which is valid. Further, making a generic statement that Erlang is “slow af” adds nothing to the discussion.


The benchmark game's "results" peg some toy programs in Erlang an order of magnitude faster than Python 3.

Of course, you probably foresaw another classic interpreter-speed justification coming from a mile away, but.... There are very well-developed methods of interfacing with fast native code, ranging from C nodes to nifs. The documentation is circumspect about using C code, but nevertheless provides you with the good, bad and the ugly on these various different methods.

If anything, I think Crystal could crib a page from Erlang and elevate what it calls "Fibers" and "Channels". Erlang made these first-class in both design & syntax, which allowed Pids and messages to be not just building blocks of concurrent interaction patterns, but also architectural utility-knifes in consecutive Erlang code. The more Erlang you read, the more you see this really powerful method of dividing concerns "physically" rather than "structurally", in which you can be doing everything from implementing Objects (for some definition of OOP) to representing recursive data structures with lightweight threads as the "backing primitive". This may be obvious to some old-head Lisp programmers, but I about choked on my latte when I saw this demonstrated at the first Erlang shop I worked in. It's a cool and extremely powerful idea that can be implemented in any language, but is best if the spawn/message syntax is concise.


Faster than Python 3 means little and the discussion is mainly about languages which compile to native code and have certain features.

Erlang is a super cool language and were I doing an app which needs millions of concurrent connections over many cores and/or machines, I'd choose it in a second. But Crystal is more of a (potential) replacement for Java or C++.


I get where you are coming from (although, in the case mentioned above at least, an order of magnitude faster places it within 150% of the speed of Java). I think you're only scratching the surface of Erlang here though. I believe "networked services", "millions of connections" and "hot-code reloading" are a meme that hides the Erlang's real utility.

Along these lines, the most popular open-source subdivision 3d modeling software package is, outside of the shaders, written top-to-bottom in Erlang (including the engine).


Erlang is slow af? That doesn't harmonize with the benchmarks I've seen, but I'm open minded. Do you have anything I can read?


It's common knowledge that it's nowhere near compiled languages for computational speed. It's advantage is massive parallelism and reliability.

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Saying Erlang is slow is like saying Ruby is slow. But both are built for problems other than crunching numbers. Not a knock on either language.

Crystal is built in the same vein as Nim - meant to be as quick as C++ but easier to write. Erlang was built for a different use case altogether.


Thanks, much appreciated.


Also shown on the benchmarks game website —

"Most (all?) large systems developed using Erlang make heavy use of C for low-level code, leaving Erlang to manage the parts which tend to be complex in other languages, like controlling systems spread across several machines and implementing complex protocol logic." (quoted from the Erlang FAQ).

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

iow the performance of apps which use Erlang a lot, is not necessarily limited by the performance of the Erlang implementation.


Last time I checked/heard about Crystal, it had support for concurrency, but not parallelism yet.


coming VERY VERY soon. They already have go-like parallelism working in a branch.


it's not very very soon - it'll be more than 2 months - but it is coming.


I wouldn't commit to any specific date. It's not something you can timebox.


That's better than 1-2 years, so like I said, very very soon


Boehm-gc -- the garbage collector used by crystal, is multi-threaded already.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: