Repository navigation
Conversation
Each free partition gets the first dependency whose children have compiled. Sort the dependencies once, while the partitions boot, by the source size of their longest chain of dependents, so the root of a long chain does not wait behind small dependencies nothing depends on. Signed-off-by: Pablo Margreff <pmargreff@gmail.com> Assisted-by: Claude Code:claude-opus-5-5
|
Thank you @pmargreff! This is great work and the PRs upstream are excellent too. Unfortunately, I am not very comfortable with the file size heuristic approach, I'd prefer something more reliable, like:
You said you already measured those but what are the numbers? If they are relatively close to the source ones (and an improvement over today), then I'd rather take those! |
|
Right, we only need something that is better than today. If we can't really distinguish those, then we pick whatever is simpler. |
|
Here are the full results. I ran the three options and the size version on nine projects: the four from before (Plausible, hexpm, Livebook, Tuist) plus Blockscout, Sequin, Lightning, Bonfire and a fresh Dependents on its own isn't in the table because I screened it out earlier: a shorter run (3 rounds at 4, 6 and 8 partitions on the first four projects) and it was behind chain length and chain length + dependents, so I left it out of the full run. Result table
Result table with Dependents length strategy included
So chain length and chain length + dependents are both better than today and about the same as size (−1.0% and −0.6% against it), and they don't have statistical difference. Chain length is ahead in Plausible and Blockscout (about 5% each), chain length + dependents in Tuist (about 4%). Numerical comparison between your proposed strategies
On the left, we have the comparison between the The notebooks, data and scripts are in https://github.com/pmargreff/mix-deps-partition-benchmark, and the Livebooks compare all the orders and have the full data in case you want to take a closer look. If that works for you, I'll open a new PR with chain length to replace this one. Seems like it's the simplest one that brings significant improvement. |
|
Beautiful work, yes, please do send a PR for chain length! |
|
Close in favor of #16193 |



With
MIX_OS_DEPS_COMPILE_PARTITION_COUNT, each free partition gets the first dependency, in converger order, whose children have compiled. The converger order says nothing about how much work comes after each dependency, so the start of a long chain can wait behind small dependencies that nothing depends on. Near the end of the build, the other partitions then have nothing to compile while that chain compiles on one of them, and the CPU sits idle. With 8 partitions on 16 cores, the CPU is idle for 45% of the Plausible build and 27% of the hexpm build.This PR cuts that idle time. It sorts the dependencies once by the source size of their longest chain of dependents: the
.ex,.erl,.xrl,.yrland C/C++ files under a dependency'slib,srcandc_src, plus the largest such value among its dependents.Results
Fresh builds of four projects (
deps/asmix deps.getleaves it, thenmix deps.compile --force), 10 rounds per partition count, with Elixirmainand this PR back to back in each round. Median build time in seconds,main→ this PR, then the median per-round change and the rounds where this PR was faster:The dashed line is a reference: a benchmark-only build of Mix that weighs each dependency by its compile time in the previous build.
Less idle CPU
Idle CPU is the share of the 16 cores' time that no partition used during the build: 16 × the build time, minus the CPU time of all partitions. Median over the rounds,
main→ this PR:Idle CPU round by round, for every project
The work barely changes: CPU time is at most 2.5% higher with this PR, so the CPU is less idle because the same work finishes sooner. Peak memory is higher in most cells, by up to 13% (Plausible with 2 partitions), and lower in a few, by up to 12% (Tuist with 2).
The idle CPU comes from partitions with nothing to compile. With 8 partitions, the partitions are busy 70% of the build instead of 61% in Plausible, and 81% instead of 69% in hexpm.
The median build of each order for Plausible with 8 partitions. Each bar is a dependency on the partition that compiled it, and the bars with a dashed outline are the critical chain, the longest chain of dependencies by serial compile time:
decimal→jason→ex_cldr→ex_cldr_currencies→ex_cldr_numbers→ex_money. Under the schedules is the number of partitions busy over time. The dashed vertical line is where the reference build finished.The interactive version of these charts, for every project and partition count, is in the schedule Livebook.
Where it does not help
Source size only sees what is in
lib,srcandc_src. When a slow dependency's cost is somewhere else, this order sends it late:makeup_erlang's 9.1 s is code that NimbleParsec generates at compile time.main(ex_cldrat 17.3 s instead of 19.5 s with 8 partitions), butex_cldr_numberstakes 21.9 s instead of 18.9 s.Shortening the critical chain
From 6 partitions on, these builds wait mostly on their critical chain, and the dependencies on it have to compile faster. I am working on identifying and addressing some of those bottlenecks in OTP or in popular Elixir dependency repos:
ex_cldr_numbersis on the critical chain of Plausible and Tuist, where it takes 13–17 s alone.beam_ssa_deadis quadratic on long chains of tests.erlconidna_mapping.erlgoes from 2.7 s to 1.4 s, and oncow_http_hd.erlfrom 4.1 s to 3.4 s.idnais in three of the four projects above, andcowlibin two.mix deps.compile timexgoes from 5.8 s to 1.4 s. Plausible and Tuist depend on timex.Other options
I also tried other weights: counting dependencies instead of bytes, sending C, Erlang and NIF dependencies first, per-language weights and a fixed cost per rebar3 dependency. None did better than source size on these projects, as the long chains are mostly Elixir packages.
Weighing each dependency by its compile time in the previous build would improve the Livebook and Tuist cases. This strategy is highlighted in most of charts as Time order, and I used it as the benchmark. Ninja tried that for its critical path scheduler (ninja-build/ninja#2019) and merged a static weight instead (ninja-build/ninja#2177). It does not seem worth it here: Mix would have to store and invalidate each dependency's compile time next to its manifest, and a first or cold build would take a different path than the builds after it.
Using only dependency depth could also work but would then favor long chain with small deps in comparison with shallow chain with big files, they are not the standard case but can still happen.
Benchmark
The notebooks, the data and the scripts are in pmargreff/mix-deps-partition-benchmark.
mainis Elixir main at 3bce30a andHEADis this PR on top of it, both built from the same tree. Since the run, the branch has been rebased on d8f5192, and the sizing has moved to a task that runs while the partitions connect; it gives the same sizes for all 627 dependencies of these projects.Each build copies
deps/asmix deps.getleft it and runsmix deps.compile --forcewithMIX_DEBUG=1on the packages thatmix deps.tree --only devlists. The projects are hexpm at 7bcd3a9, Plausible at 418da46, theserverdirectory of the Tuist repository as of 2026-11-19, and Livebook at 427774a.The machine is an Intel Core Ultra 9 285HX (8 P-cores, 16 E-cores) with 48 GB of memory, running Linux 7.2 and OTP 29.1.2.
taskset -c 8-23), and every partition VM inherits that, so no partition lands on a faster P-core.systemd-run --user --scope), only to measure the peak memory and CPU time of all its partitions together.Benchee takes all the samples of a scenario back to back, which would run every
mainbuild before everyHEADbuild. Instead:main, again(the noise check) runs at 8 partitions in every round. The benchmark-only build of Mix also ran in some rounds; the script and the output below leave it out.Benchmark script
Benchee output
AI disclosure
I used Claude Code (Claude Opus 5.5) to analyze the scheduler, write the change and its test, and run the benchmarks. I reviewed and validated the code and the results myself.