-
Notifications
You must be signed in to change notification settings - Fork 24k
copy: Reduce calls to stat() by 50% in chown_recursive #75741
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 e 10000 mails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Conversation
…rent This merges implementations of `AnsibleModule.set_owner_if_different()` & `AnsibleModule.set_group_if_different()` into a single method. The benefits are - reduction in code duplication - makes possible halving the number of calls to `os.lchown()` when the copy module sets both owner and group. There should be no outward change in behavior. The two original methods become thin wrappers around the new one. This PR is related to ansible#75741. If both are merged, then the second benefit above can be realised - by replacing calls in `copy.chown_recursive()`. Open questions: - Should this new method be public (without a leading underscore)? - Is there a better name?
c812433
to
bd42af2
Compare
…rent This merges implementations of `AnsibleModule.set_owner_if_different()` & `AnsibleModule.set_group_if_different()` into a single method. The benefits are - reduction in code duplication - makes possible halving the number of calls to `os.lchown()` when the copy module sets both owner and group. There should be no outward change in behavior. The two original methods become thin wrappers around the new one. This PR is related to ansible#75741. If both are merged, then the second benefit above can be realised - by replacing calls in `copy.chown_recursive()`. Open questions: - Should this new method be public (without a leading underscore)? - Is there a better name?
Some profiling of an extreme case, calls to lstat are cut by 50% SetupCreate a deep directory tree of approx 18 000 nodes
Without
With
|
bd42af2
to
1e0134b
Compare
Rebased on devel, and included the headline number in the summary |
…rent This merges implementations of `AnsibleModule.set_owner_if_different()` & `AnsibleModule.set_group_if_different()` into a single method. The benefits are - reduction in code duplication - makes possible halving the number of calls to `os.lchown()` when the copy module sets both owner and group. There should be no outward change in behavior. The two original methods become thin wrappers around the new one. This PR is related to ansible#75741. If both are merged, then the second benefit above can be realised - by replacing calls in `copy.chown_recursive()`.
…rent This merges implementations of `AnsibleModule.set_owner_if_different()` & `AnsibleModule.set_group_if_different()` into a single method. The benefits are - reduction in code duplication - makes possible halving the number of calls to `os.lchown()` when the copy module sets both owner and group. There should be no outward change in behavior. The two original methods become thin wrappers around the new one. This PR is related to ansible#75741. If both are merged, then the second benefit above can be realised - by replacing calls in `copy.chown_recursive()`.
1e0134b
to
13e8188
Compare
The test
|
13e8188
to
60cbd7f
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@moreati would you mind rebasing? |
on it |
60cbd7f
to
fdbe6be
Compare
…rent This merges implementations of `AnsibleModule.set_owner_if_different()` & `AnsibleModule.set_group_if_different()` into a single method. The benefits are - reduction in code duplication - makes possible halving the number of calls to `os.lchown()` when the copy module sets both owner and group. There should be no outward change in behavior. The two original methods become thin wrappers around the new one. This PR is related to ansible#75741. If both are merged, then the second benefit above can be realised - by replacing calls in `copy.chown_recursive()`. Open questions: - Should this new method be public (without a leading underscore)? - Is there a better name?
This reduces the number of times `stat()` or `chown()` are called by the copy module. Reductions come from - combining loops for owner and group, thus not looping twice - not looping over the list of directories returned by `os.walk()`, each directory is already handled when `os.walk()` descends into it Possible further reductions could be achieved by - exiting early from the check_mode loop - Replacing `m.set_owner_if_different()` & `m.set_group_if_different()` calls with a single method. I propose to do these separately, if there is interest.
fdbe6be
to
4e654c7
Compare
Notes to self:
|
check the action plugin, it has it's own 'recursive' code and might need mirroring of these changes |
ok, I'll try to take a look tomorrow. |
I don't think The other major directory walking code I'm aware of are the |
no, separate is fine, just wanted to make sure they kept as in sync as possible ... hate the duplicity |
FYI, I have an alternative PR that simplifies this bit of code further #84313. |
SUMMARY
This reduces the number of times
lstat()
orchown()
are called by the copy module. Reductions come fromos.walk()
, each directory is already handled whenos.walk()
descends into itISSUE TYPE
COMPONENT NAME
copy
ADDITIONAL INFORMATION
Possible further reductions could be achieved by
I propose to do these seperately, if there is interest.