Change implementation of remove_dir_all from recursive to an iterative version#154829
Open
asder8215 wants to merge 1 commit intorust-lang:mainfrom
Open
Change implementation of remove_dir_all from recursive to an iterative version#154829asder8215 wants to merge 1 commit intorust-lang:mainfrom
asder8215 wants to merge 1 commit intorust-lang:mainfrom
Conversation
Collaborator
|
r? @jhpratt rustbot has assigned @jhpratt. Use Why was this reviewer chosen?The reviewer was selected based on:
|
asder8215
commented
Apr 5, 2026
| // in the ReadDir struct through a method that return &Path, we can reduce memory usage | ||
| // allocated to this VecDeque. | ||
|
|
||
| let mut directories = VecDeque::new(); |
Contributor
Author
There was a problem hiding this comment.
Also, noting that this could use the std library LinkedList implementation if the resizing cost from VecDeque is undesirable.
e933993 to
a2793e4
Compare
Member
|
@rustbot reroll |
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.
This PR essentially changes the underlying
remove_dir_allimplementation used by unix and I believe uefi platforms from a recursive-based approach to an iterative version. The order it removes directories and files from the recursive version should be preserved in this iterative version. I'm curious if this iterative approach could show any performance improvement over the current recursive based approach thatremove_dir_allhas on unix/uefi platforms.I also made a comment on how this iterative-based approach is redundantly holding a
PathBufin the tuple (which could incur a big allocation cost if we are removing deeply nested directories). This could be optimized if we are able to retrieve a reference to the path thatReadDirstruct is holding, as it contains this information in itsInnerReadDir'srootfield; I believe this would also make the iterative approach allocate less memory than the recursive approach as we would only need the main directory/nested directories&Pathvalues when we are removing it.I can make an ACP for
ReadDirstruct root path to be accessible via a method if that would be appropriate.