Skip to content

Conversation

@straight-shoota
Copy link
Member

When running specs with execution contexts, it's annoying to have to explicitly scale the default execution context in order to get actual parallelism. This could be handled in some kind of spec helper, but it would still require extra effort and it'd be easy to miss out on it.

Thus, I'm suggesting to resize the EC in the stdlib spec package (i.e. for any spec program) if the environment variable CRYSTAL_WORKERS is defined.

Extracted from #16339

@ysbaddaden
Copy link
Contributor

ysbaddaden commented Nov 28, 2025

NOTE: the reason we don't handle CRYSTAL_WORKERS with execution contexts by default is for applications to opt-in to MT if they want to, when they want to (so they can initialize single-threaded, or prefer to start explicit contexts) and to use their own controls like CLI argument, custom ENV variable, file configuration, ...

A rogue CRYSTAL_WORKERS in the environment shouldn't affect an applications' behavior.

And... now I'm having second thoughts about using it in spec 😅

I guess unlike prelude that's always required and executed before applications can do anything, you can require spec after requiring your app.

@straight-shoota
Copy link
Member Author

I suppose we could put this behind another feature flag which keeps being opt-in even when -Dexecution_context becomes the default. Maybe that makes sense in general...?
An -Dmt flag which automatically resizes the default context?
Let's keep thinking about that. But I think this is fine for now as we try to set up CI for execution contexts.

@straight-shoota straight-shoota added this to the 1.19.0 milestone Nov 28, 2025
@ysbaddaden
Copy link
Contributor

Yes, I believe it's fine for spec 👍

@straight-shoota straight-shoota self-assigned this Dec 2, 2025
@straight-shoota straight-shoota merged commit 412ec28 into crystal-lang:master Dec 2, 2025
42 checks passed
@straight-shoota straight-shoota deleted the feat/spec-parallel branch December 2, 2025 13:27
ysbaddaden added a commit that referenced this pull request Dec 2, 2025
We shall resize the `default` execution context (parallel), not the `current` context (may be an isolated context).
ysbaddaden added a commit that referenced this pull request Dec 2, 2025
…6471)

We shall resize the `default` execution context (parallel), not the `current` context (may be an isolated context).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants