Repository navigation
[perf] Optimize controller status queries - #245
Merged
ji-huazhong merged 2 commits intoNov 30, 2026
Merged
Conversation
Signed-off-by: ji-huazhong <hzji210@gmail.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
0oshowero0
approved these changes
Nov 30, 2026
0oshowero0
reviewed
Nov 30, 2026
Comment on lines
1939
to
1942
| row = (partition.production_status[global_index] == 1).tolist() | ||
| ready[key] = sorted( | ||
| name for name, col in partition.field_name_mapping.items() if col < len(row) and row[col] == 1 | ||
| name for name, col in partition.field_name_mapping.items() if col < len(row) and row[col] | ||
| ) |
Collaborator
There was a problem hiding this comment.
Nit: we can convert the row directly with .tolist() and keep the existing row[col] == 1 check:
Suggested change
| row = (partition.production_status[global_index] == 1).tolist() | |
| ready[key] = sorted( | |
| name for name, col in partition.field_name_mapping.items() if col < len(row) and row[col] == 1 | |
| name for name, col in partition.field_name_mapping.items() if col < len(row) and row[col] | |
| ) | |
| row = partition.production_status[global_index].tolist() | |
| ready[key] = sorted( | |
| name for name, col in partition.field_name_mapping.items() if col < len(row) and row[col] == 1 | |
| ) |
This avoids allocating a temporary bool tensor per key for == 1 (roughly 2x faster in the Python loop for 256+ keys) while keeping the diff smaller and preserving the exact == 1 readiness check.
Signed-off-by: ji-huazhong <hzji210@gmail.com>
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.
Problem
Python Controller status queries do unnecessary work before returning their results. Consumption queries call Python
max()on an already sorted index tensor, comparing one scalar tensor at a time. Masked production queries first copy every allocated row for the requested columns and then select the partition's rows, which is expensive for small partitions with high global indexes. KV readiness queries also convert scalar tensors to Python booleans separately for each field.Changes
kv_exists, convert each integer status row directly and check== 1in Python, avoiding both per-field scalar Tensor conversions and a temporary boolean Tensor per key.Public APIs, return ordering, readiness semantics, and result isolation are preserved. This adds no cache or invalidation state.
Validation
Strengthen the existing production-status test with different per-row and per-field states, reordered and repeated fields, sparse indexes, reserved rows, and result mutation. Add two assertions to the existing finalize end-to-end test to verify that
kv_existshides unfinalized fields and exposes them after finalization. No test functions or mocks are added.python -m compileall -q transfer_queue tutorial tests: passed.test_opt_out_keeps_the_process_alive_for_inspectionfails in the full-suite order, and six Yuanrong fixtures lack the optionaldatasystemSDK. All tests affected by this change pass.Performance
Compared with main at
eb39cc4, using real local ZMQ requests, one PyTorch CPU thread, five warmup calls, and nine alternating blocks of 20 calls per implementation. Values are medians of the block-average latencies.kv_exists, 256 keys, 16 fieldsDirect
kv_existscalls for the same 256 keys and 16 fields take 10.454 ms on main and 0.497 ms with this change (95.2% lower latency), measured with nine alternating blocks of 50 calls. This excludes RPC overhead; the table above includes it.For the sparse production query, the status tensor has 139,266 allocated rows. CPU profiling shows the old indexing path allocates a 1,114,128-byte intermediate result and a 512-byte selected result; the new path allocates only the 512-byte selected result.
The dense production query shows no speedup. These measurements establish improvements in the listed query workloads, not a training-throughput gain.