Repository navigation
Document and constrain WorkQueue.maxConcurrency - #120
Merged
Merged
Conversation
- The clamping range is public as WorkQueue.concurrencyRange, so callers can validate their own input instead of discovering the clamp after the fact. - The property and the initializer share one clamp helper instead of duplicating `max(1, min(256, ...))`. - maxConcurrency's documentation now states the clamping and documents the previously undocumented mid-run behaviour: raising the limit takes effect on the next refill, lowering it does not interrupt running processWork calls, so concurrency can briefly exceed the new limit. - setMaxConcurrency stays, but its documentation explains why it exists rather than reading as a redundant duplicate: Swift only permits mutating actor state from inside the actor, so it is the supported way to change the limit from outside. Tests - Clamping is asserted against concurrencyRange instead of hard-coded numbers. - New test that raising the limit mid-run actually increases observed parallelism, which is the behaviour the docs now promise. Fixes #99
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WorkQueue.maxConcurrencyhad two ways to set it, an invisible clamp, and undocumented mid-run behaviour. This addresses all three.Changes
The clamp is now discoverable
Callers can validate their own input instead of discovering the clamp after the fact. The property setter and the initializer now share one
clamphelper rather than duplicatingmax(1, min(256, ...))in two places.The clamping and mid-run behaviour are documented
That last paragraph was previously undocumented, and it's the non-obvious part: raising works promptly, lowering is not retroactive.
setMaxConcurrencykept, but justifiedI initially removed it, then found it is not actually redundant:
Swift only permits mutating actor state from inside the actor, so a caller outside the actor cannot write
queue.maxConcurrency = 8— the method is the supported path. Its documentation now says so instead of reading as a duplicate:Testing
concurrencyRangerather than hard-coded256/1.maxConcurrency: 1, raises to 8 after 50 ms, and asserts the peak concurrentprocessWorkcount exceeded 1.Verified:
194 tests pass,
swiftformat --lintclean, DocC builds with--warnings-as-errors.Breaking changes
None —
setMaxConcurrencyis retained andconcurrencyRangeis additive.Closes #99