perf(formatter): use VecDeque for member chain groups#18094
Merged
graphite-app[bot] merged 1 commit intomainfrom Jan 19, 2026
Merged
perf(formatter): use VecDeque for member chain groups#18094graphite-app[bot] merged 1 commit intomainfrom
graphite-app[bot] merged 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the formatter's member chain handling by replacing Vec with VecDeque for storing tail chain groups. The change improves the performance of pop_first() operations from O(n) to O(1), which benefits formatting of long member chains.
Changes:
- Replaced
VecwithVecDequeforTailChainGroupsandMemberChainGroupsBuilderstorage - Updated all collection operations to use VecDeque-specific methods (
push_back,pop_front,front,back) - Refactored
any_except_last_will_break()to use iterator-based approach compatible with VecDeque
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
Dunqing
approved these changes
Jan 19, 2026
Member
Merge activity
|
## Summary - Replace `Vec` with `VecDeque` for `TailChainGroups` storage - `pop_first()` now uses `pop_front()` which is O(1) instead of O(n) `remove(0)` ## Changes | Operation | Before | After | |-----------|--------|-------| | `pop_first()` | `remove(0)` - O(n) shift | `pop_front()` - O(1) | | `first()` | `first()` | `front()` | | `last()` | `last()` | `back()` | | `push` | `push()` | `push_back()` | ## Impact Improves performance when formatting long member chains like `a.b().c().d().e()` where the first group may be merged with the head. ## Test plan - [x] `cargo test -p oxc_formatter` passes (144 tests) - [x] Prettier conformance unchanged (97.77% js, 96.37% ts) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
eef381a to
138637c
Compare
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.
Summary
VecwithVecDequeforTailChainGroupsstoragepop_first()now usespop_front()which is O(1) instead of O(n)remove(0)Changes
pop_first()remove(0)- O(n) shiftpop_front()- O(1)first()first()front()last()last()back()pushpush()push_back()Impact
Improves performance when formatting long member chains like
a.b().c().d().e()where the first group may be merged with the head.Test plan
cargo test -p oxc_formatterpasses (144 tests)🤖 Generated with Claude Code