Repository navigation
Fill one sample array as batches arrive - #21
Merged
Merged
Conversation
…atenating them A split sample forecast kept every batch's samples until the end and then concatenated them, so the batches and the merged array were alive at once: twice the samples at peak. The merged array is now allocated when the first batch arrives and each batch is copied into its rows, by batch index, and released straight away; the pool path consumes batches as they complete. Validation, error messages, metadata and the read-only result are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MmmpKxPmMsizeHZNSWLEdc
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.
When a sample forecast is split into batches, the client keeps every batch and then builds the merged result, so memory briefly doubles. This allocates the merged array once, copies each batch into its slot (by batch index, so results are identical whatever order batches finish in), and lets each batch go as soon as it's copied. The pool path now picks up batches as they complete.
jfm-mcp measured about 2.9x the sample array at peak for a 20,000-sample forecast (1.45 GB for a 507 MB array); the merge step itself drops from 2x to roughly 1x plus one batch (1014 MB to 634 MB in a local check with 4 batches).
The merged array stays read-only, because the README, API reference and
SampleForecastResultdocstring all promise read-only forecast arrays.Validation, error messages and result metadata are unchanged; new tests cover batch order on both paths (including out-of-order pool completion), the existing checks, and that each batch is freed before the next one is fetched.
🤖 Generated with Claude Code
https://claude.ai/code/session_01MmmpKxPmMsizeHZNSWLEdc
Note
Medium Risk
Refactors how split sample forecasts are assembled and parallel pool completion order, but behavior and error contracts are preserved and covered by new tests.
Overview
Sample forecast batching no longer keeps every batch alive until a final
np.concatenate. A new_SampleBatchMergerpre-allocates the full merged sample array on the first batch, copies each batch into fixed row ranges frombatch_sizes(order-independent), and drops batch arrays after copy.The sequential path feeds batches into the merger as they return. The pool path switches from
executor.maptoas_completed, merging each finished batch immediately instead of waiting for all peers. Contract checks andJointFMServiceErrorwrapping are unchanged; per-batch shape mismatch detection was added so short batches cannot broadcast silently.tests/test_sample_batch_merge.pycovers correct concatenation (single endpoint and pool, including out-of-order completion), read-only merged arrays, metadata mismatch errors, missing batches, and batch lifetime behavior.Reviewed by Cursor Bugbot for commit ef29a24. Configure here.