par-map: chunking strategy and cancellation (ILO-354)#670
Merged
Conversation
Collaborator
Author
|
needs manual rebase (conflicts in: src/builtins.rs) |
Collaborator
Author
|
needs manual — rebase conflict in non-doc file(s) |
11a0d90 to
0efac38
Compare
|
0efac38 to
11a0d90
Compare
Collaborator
Author
|
needs manual rebase — touches src/builtins.rs, src/interpreter/mod.rs, src/vm/mod.rs |
Implements `par-map fn xs [n]` — a general concurrency primitive that applies a function to each element of a list in parallel, up to `n` items at a time (default: num_cpus; override via ILO_PAR_MAP_CONCURRENCY). Returns `L (R b t)`: per-item Ok/Err in input order without short-circuit. Tree-walker implementation using std::thread::scope with chunked batches, following the get-many pattern. VM/Cranelift bail to tree via the existing bridge (is_tree_bridge_eligible). Large handler extracted into #[inline(never)] par_map_run per the ILO-289 dispatch-arm-size convention. Touches: src/builtins.rs, src/interpreter/mod.rs, src/parser/mod.rs, src/verify.rs, src/vm/mod.rs, SPEC.md, ai.txt, skills/ilo/ilo-builtins-io.md, examples/par-map.ilo. Includes 3 interpreter tests. Closes ILO-67. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the wave-by-wave one-item-per-thread dispatch with an
auto-tuned chunking strategy: spawn at most `concurrency` threads,
each processing `ceil(len / concurrency)` items. This keeps
thread-creation overhead constant for large lists of small items.
Add cooperative cancellation via a shared `AtomicBool`: the first
worker to encounter a `RuntimeError` sets the flag; subsequent items
inside any worker are skipped and filled with a cancellation sentinel
`Err("par-map: cancelled due to earlier error")`.
Add three new unit tests (ILO-354):
- `par_map_large_list_chunking` — 100-item order-preservation check
- `par_map_error_cancels_remaining_workers` — cancellation on error
- `par_map_chunk_size_formula` — unit test for the auto-tuning formula
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
11a0d90 to
233f096
Compare
Collaborator
Author
|
mini pc is reviewing this |
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
ceil(len / concurrency)), spawning at mostconcurrencythreads each processing a slice of items. Constant thread overhead regardless of list length.AtomicBoolflag — first worker to hit aRuntimeErrorsets it; remaining unstarted items are skipped with aErr("par-map: cancelled due to earlier error")sentinel.par_map_large_list_chunking,par_map_error_cancels_remaining_workers,par_map_chunk_size_formula.Extends ILO-67 / PR #610.
Test plan
cargo test par_map— all 6 tests pass🤖 Generated with Claude Code