Skip to content

Conversation

@ysbaddaden
Copy link
Contributor

@ysbaddaden ysbaddaden commented Nov 28, 2025

We just enabled MT in #16380 but we can go further and enable execution context as suggested in the PR, by merely resizing the default context to the default workers count.

Also changes the default --threads value to also be the default workers count, which is CRYSTAL_WORKERS when specified and valid, and defaults to the number of available logical CPUs instead of being hardcoded to 4 threads (default for preview_mt) or 8 forked processes (arbitrary number).

It might be faster, on my computer recompiling Crystal went from ~17s to ~15s but your mileage may vary.

@ysbaddaden
Copy link
Contributor Author

ysbaddaden commented Nov 28, 2025

I'll have to verify but rusage seems to say that the distinct codegen context might lead to less context switches, less kernel time and less cpu time, for the same wall time 🕐

No, both builds behave the same, just sometimes we get a lucky run with less of everything (but wall time). Maybe there could be some profiling to understand how to improve efficiency.

@yxhuvud
Copy link
Contributor

yxhuvud commented Nov 28, 2025

What command(s) do you use to benchmark it? When I try it seems to spend a miniscule part in multithreaded code, but perhaps I'm doing something wrong.

@ysbaddaden
Copy link
Contributor Author

I use rusage from cosmopolitan and run the following to recompile the compiler:

$ make release=1
$ rm -rf ~/.cache/crystal
$ rusage make -B

It doesn't spend much time in MT, but it uses lots of cores and CPU time adds up.

@straight-shoota straight-shoota merged commit 2fd8534 into crystal-lang:master Dec 2, 2025
40 of 43 checks passed
@github-project-automation github-project-automation bot moved this from Review to Done in Multi-threading Dec 2, 2025
@ysbaddaden ysbaddaden deleted the feature/compiler-use-execution-context branch December 2, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants