Skip to content

par-map: chunking strategy and cancellation (ILO-354)#670

Merged
danieljohnmorris merged 3 commits into
mainfrom
feature/par-map-chunking
May 22, 2026
Merged

par-map: chunking strategy and cancellation (ILO-354)#670
danieljohnmorris merged 3 commits into
mainfrom
feature/par-map-chunking

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

  • Chunking: replace wave-by-wave one-item-per-thread dispatch with auto-tuned chunk size (ceil(len / concurrency)), spawning at most concurrency threads each processing a slice of items. Constant thread overhead regardless of list length.
  • Cancellation: shared AtomicBool flag — first worker to hit a RuntimeError sets it; remaining unstarted items are skipped with a Err("par-map: cancelled due to earlier error") sentinel.
  • Tests (ILO-354): 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
  • Existing par-map tests (order, empty list, default concurrency) unaffected
  • Large list (100 items) processes in correct order across multiple chunks
  • Error at item 5 with concurrency=1 cancels items 6–9

🤖 Generated with Claude Code

@danieljohnmorris danieljohnmorris added the mini Created by mini PC autonomous workflow label May 22, 2026
@danieljohnmorris
Copy link
Copy Markdown
Collaborator Author

needs manual rebase (conflicts in: src/builtins.rs)

@danieljohnmorris
Copy link
Copy Markdown
Collaborator Author

needs manual — rebase conflict in non-doc file(s)

@danieljohnmorris danieljohnmorris force-pushed the feature/par-map-chunking branch from 11a0d90 to 0efac38 Compare May 22, 2026 10:36
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@danieljohnmorris danieljohnmorris force-pushed the feature/par-map-chunking branch from 0efac38 to 11a0d90 Compare May 22, 2026 11:06
@danieljohnmorris
Copy link
Copy Markdown
Collaborator Author

needs manual rebase — touches src/builtins.rs, src/interpreter/mod.rs, src/vm/mod.rs

Daniel Morris and others added 3 commits May 22, 2026 18:45
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>
@danieljohnmorris danieljohnmorris force-pushed the feature/par-map-chunking branch from 11a0d90 to 233f096 Compare May 22, 2026 17:47
@danieljohnmorris
Copy link
Copy Markdown
Collaborator Author

mini pc is reviewing this

@danieljohnmorris danieljohnmorris merged commit 734d530 into main May 22, 2026
6 of 11 checks passed
@danieljohnmorris danieljohnmorris deleted the feature/par-map-chunking branch May 22, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mini Created by mini PC autonomous workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant