Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcnb: Remove use of the stacker crate #517

Merged
merged 1 commit into from
Oct 17, 2022
Merged

Conversation

edmorley
Copy link
Member

Since:

In addition:

  • The function has been refactored to avoid recursing for every file (now only directories), which reduces depth of recursion by one, and saves an additional stat on every file, since the file type is already retrieved by read_dir so it's redundant to call the more expensive symlink_metadata() again on the next recursion.
  • remove_recursively has been renamed to remove_dir_recursively to more clearly reflect it's intended to operate on directories (and for closer parity to the name of remove_dir_all).

Closes #516.
GUS-W-11917787.

@edmorley edmorley added libcnb faster compiles Things that improve compile times labels Oct 17, 2022
@edmorley edmorley self-assigned this Oct 17, 2022
Since:
- The stdlib `remove_dir_all` recursive implementation (which this
  function is replacing) doesn't have stack overflow protection
- Testing has proven it's unnecessary (see #516)

In addition:
- The function has been refactored to avoid recursing for every file
  (now only directories), which reduces depth of recursion by one,
  and saves an additional stat on every file, since the file type is
  already retrieved by `read_dir` so it's redundant to call the more
  expensive `symlink_metadata()` again on the next recursion.
- `remove_recursively` has been renamed to `remove_dir_recursively`
   to more clearly reflect it's intended to operate on directories (and for
   closer parity to the name of `remove_dir_all`)

GUS-W-11917787.
@edmorley edmorley marked this pull request as ready for review October 17, 2022 10:52
@edmorley edmorley requested a review from a team as a code owner October 17, 2022 10:52
Copy link
Member

@Malax Malax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking, this PR makes a trade-off I wouldn't usually make (no surprise as the changed code was originally written by me 😄). When dealing with recursion I'd rather have a larger(-ish) binary (and the additional compile time for that code) and be sure that we won't smash the stack. I find debugging stack overflows rather hard, when the stack size varies across operating systems, configurations, optimisation level, etc. Especially when the code relies on external state (the FS in this case) that might be required to reproduce the issue.

In practice, removing the code that prevents stack overflows is probably fine in this context, as demonstrated by your testing. I therefore won't block this from merging.

@edmorley edmorley merged commit d8d291d into main Oct 17, 2022
@edmorley edmorley deleted the edmorley/rm-stacker branch October 17, 2022 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
faster compiles Things that improve compile times libcnb
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reconsider the use of stacker in remove_recursively()
2 participants