What if you will use escript for collect and compile files(as it’s done in rebar3)? I suppose it would be very flexible. But if you want use some Makefile - I suppose you need try to take a look to erlang.mk - exactly to erlang.mk#core/erlc.mk.
I could write a multicore program that uses the compile module, but I am surprised that it would be required. It is such a normal thing for Erlang programs to be multicore that I didn’t consider for a second that that erlc wouldn’t be; not even with a flag or such.
Could you share what you did precisely? I just tested again with 10,000 modules with just a declaration and I got a single erlc process using less than 1 CPU core, spread across a few cores due to the OS scheduler bouncing it around a little. It didn’t manage to max out 1, let alone the other 7.
louis ~/Desktop/test $ for i in (seq 1 10000)
echo "-module(mod$i)." >> src/mod$i.erl
end
louis ~/Desktop/test $ erlc -o ebin -server src/*.erl &
louis ~/Desktop/test $ ps -A -o %cpu | awk '{s+=$1} END {print s "%"}'
185.3%
Here you can see erlc + all the other programs I’m currently running are using less than 2 cores fully. I can tell you from htop that erlc isn’t even the majority of that.
Yeah, that’s precisely what I did, but just eye balled things tbh. As far as the ps + awk command, I saw as much as 300%, prior to running I was at about 100% for current procs Maybe my eye balling effort was deceived by what’s your talking about with the OS scheduler bouncing around.
If I’m tracing code correctly, I don’t think you’re going to get what you want right now. It looks like erlc with the server option will fire up the compile server, the arguments are passed to the compile server, this in turn simply calls erl_compile:compile/2. This seems like it will compile one file at a time. There is no attempt to batch files ( num_files / num_cores) or spawning of any kind at that point.
That’s if I did my tracing correctly (and I’m rushing right now tbh). Of course, if I am right, it looks like wedging in what you’re after wouldn’t be a big PR. However, I have to wonder why that hasn’t been done yet.
Edit: Of course as you know, dependencies between modules would have to be taken into account with such a PR.
The compile server will not help when used like this. All files given on the command line to one invocation of erlc will be compiled sequentially.
erlc was written a long time ago, long before OTP R11 that introduced SMP support. Without SMP support, running compilation jobs in parallel would only be slower. Also, erlc is often used from within a Makefile, meaning that there would be one invocation of erlc for each file. Adding support for compiling all files given on the command line in parallel would not have improved the usual way erlc was used.
As a side note : Elixir’s parallel compiler is an interesting read. There was also a discussion with folks such as @jhogberg and @MononcQc around a next-generation erlang compiler. I can’t find that conversation right now.
As another side note, despite erlc compiling one file at a time (as a default), man it is fast
We had a discussion in the Build Tools and Packaging WG earlier this year, but I haven’t been able to work much on it lately. I hope to revisit it for OTP 26.