builtins.groupBy: Drop ValueVectorMap#536
Merged
Merged
Conversation
Apply the same optimization to builtins.groupBy as to builtins.zipAttrsWith (162a34378c): instead of accumulating the groups in a std::map<Symbol, ValueVector> with traceable_allocator - which costs a GC_MALLOC_UNCOLLECTABLE() per distinct name plus traceable growth allocations for every per-group vector, all taking the global GC allocation lock - collect the (name, value) pairs into a plain std::vector and group them by stable-sorting on the name. The vector doesn't need to be visible to the GC since the values it points to are kept alive by the list in args[1] for the duration of the call. The shared machinery (the NameValue type, sorting/counting the names, and iterating over the per-name runs) is factored out into helpers used by both primops. This removes the last user of ValueVectorMap, so drop that typedef. Assisted-by: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis change refactors ChangesGrouping helper refactor
Estimated code review effort: 2 (Simple) | ~15 minutes Related PRs: None identified. Suggested labels: refactor, libexpr Suggested reviewers: None identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
cole-h
approved these changes
Jul 6, 2026
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.
Motivation
Apply the same optimization to
builtins.groupByas tobuiltins.zipAttrsWithin #535, and factor out some shared code. This removes the need for theValueVectorMap.Context
Summary by CodeRabbit