refactor: Use real iterators over nodes#375
Open
Peeja wants to merge 2 commits intofeat/faster-index-generationfrom
Open
refactor: Use real iterators over nodes#375Peeja wants to merge 2 commits intofeat/faster-index-generationfrom
Peeja wants to merge 2 commits intofeat/faster-index-generationfrom
Conversation
0a6f00f to
d4ff53d
Compare
0be118d to
67683a6
Compare
d4ff53d to
f3ae0c5
Compare
volmedo
approved these changes
Mar 5, 2026
| NodesByShard(ctx context.Context, shardID id.ShardID, startOffset uint64) ([]dagsmodel.Node, error) | ||
| // ForEachNodeInShard iterates over all the nodes for a given shard, in the | ||
| // order they should appear in the shard. | ||
| ForEachNodeInShard(ctx context.Context, shardID id.ShardID, startOffset uint64) iter.Seq2[NodeInShard, error] |
Member
There was a problem hiding this comment.
nit, likely subjective preference: I'd find the name of iterator functions to be more idiomatic if the "ForEach" was dropped and the plural was used. I'd call them just NodesInShard and NodesInIndex. Personally, the resulting "for node = range for each node..." feels a bit awkward and redundant 🙂.
Comment on lines
+365
to
+366
| yield(blobs.NodeInIndex{}, fmt.Errorf("failed to prepare statement: %w", err)) | ||
| return |
Member
There was a problem hiding this comment.
nit: iterator functions should check what yield returns and only return if yield == false. That lets the caller decide whether the loop should end in case of error.
In this specific case it's not a huge deal because these errors will likely happen for every element, but I think checking the result of yield would be nice from a correctness standpoint.
Peeja
added a commit
that referenced
this pull request
Mar 9, 2026
Especially for indexes with many shards, this is dramatically faster. We were finding the shards in the index, and then for each shard, looping over the nodes/slices. Now we find all of the nodes in a single query. It doesn't even matter what order they come in in, as long as we see them all. #### PR Dependency Tree * **PR #360** 👈 * **PR #361** * **PR #362** * **PR #363** * **PR #364** * **PR #365** * **PR #366** * **PR #375** This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal)
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.
In response to #354 (comment)
PR Dependency Tree
This tree was auto-generated by Charcoal