Skip to content

Conversation

@kim-em
Copy link
Collaborator

@kim-em kim-em commented Dec 2, 2025

This PR adds optional chunking support to the par and par' functions in Lean.Elab.Parallel for CoreM, MetaM, TermElabM, and TacticM. This reduces task creation overhead when there are many small jobs by grouping them into chunks that run sequentially within each parallel task.

New optional parameters

  • maxTasks : Nat := 0 - Maximum number of parallel tasks (0 = no limit, original behavior)
  • minChunkSize : Nat := 1 - Minimum jobs per chunk

Example

With 1000 jobs and maxTasks := 128, minChunkSize := 8:

  • Chunk size = max(8, ceil(1000/128)) = 8
  • Creates ~125 parallel tasks instead of 1000

Backward compatibility

Default behavior (maxTasks = 0) is unchanged - one task per job. Existing code continues to work without modification.

🤖 Prepared with Claude Code

@kim-em kim-em marked this pull request as draft December 2, 2025 01:53
@kim-em kim-em added the changelog-language Language features and metaprograms label Dec 2, 2025
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Dec 2, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Dec 2, 2025

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase c0d5b9b52c31c181db0902b4cc107459f9df6563 --onto 5bd331e85d9d110a29fb3367dbb21854010ffcbd. You can force Mathlib CI using the force-mathlib-ci label. (2025-12-02 02:46:54)
  • ✅ Mathlib branch lean-pr-testing-11467 has successfully built against this PR. (2025-12-02 09:34:08) View Log

@leanprover-bot
Copy link
Collaborator

leanprover-bot commented Dec 2, 2025

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase c0d5b9b52c31c181db0902b4cc107459f9df6563 --onto d3dda9f6d4428a906c096067ecb75e432afc4615. You can force reference manual CI using the force-manual-ci label. (2025-12-02 02:46:55)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2025-12-01 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2025-12-02 08:32:49)

This PR adds optional chunking support to the `par` and `par'` functions in
`Lean.Elab.Parallel` for CoreM, MetaM, TermElabM, and TacticM. This reduces
task creation overhead when there are many small jobs by grouping them into
chunks that run sequentially within each parallel task.

New optional parameters:
- `maxTasks : Nat := 0` - Maximum number of parallel tasks (0 = no limit)
- `minChunkSize : Nat := 1` - Minimum jobs per chunk

Example: With 1000 jobs and `maxTasks := 128, minChunkSize := 8`:
- Chunk size = max(8, ceil(1000/128)) = 8
- Creates ~125 parallel tasks instead of 1000

Default behavior (maxTasks = 0) is unchanged - one task per job.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@kim-em kim-em force-pushed the feat/chunked-parallel branch from db85607 to 66db5e9 Compare December 2, 2025 07:29
Add `parIterWithCancelChunked` functions for CoreM, MetaM, TermElabM, and TacticM that support chunking jobs into groups to reduce task creation overhead.

The original `parIterWithCancel` functions remain unchanged for backward compatibility. The new chunked variants accept `maxTasks` and `minChunkSize` parameters to control parallelism.

This enables PRs that use `parIterWithCancel` (like parallel library search and rewrites) to benefit from chunking by switching to the new `parIterWithCancelChunked` function with `maxTasks := 128`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@kim-em kim-em force-pushed the feat/chunked-parallel branch from 66db5e9 to 272f0f5 Compare December 2, 2025 07:36
@kim-em kim-em changed the base branch from master to nightly-with-mathlib December 2, 2025 07:43
@kim-em kim-em removed the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Dec 2, 2025
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Dec 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Dec 2, 2025
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-language Language features and metaprograms toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants