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

Optimize fs.scandir #37

Merged
merged 2 commits into from
Nov 27, 2019
Merged

Optimize fs.scandir #37

merged 2 commits into from
Nov 27, 2019

Conversation

jwnimmer-tri
Copy link
Contributor

@jwnimmer-tri jwnimmer-tri commented Nov 20, 2019

Closes #36.

This is my best cut so far. I didn't immediately see how to run the tests locally, so hopefully Travis will tell me. (I did test as a monkey patch within my application integration.)

When DirectoryExpected is raised the backtrace is a bit heavy -- is has the two prior exceptions shown as well. I tried some control flow phrasings to work around this, but found them all a bit too awkward.

Happy to take any feedback.

@codecov
Copy link

codecov bot commented Nov 20, 2019

Codecov Report

Merging #37 into master will increase coverage by 0.13%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #37      +/-   ##
=========================================
+ Coverage   96.96%   97.1%   +0.13%     
=========================================
  Files           5       5              
  Lines         330     345      +15     
=========================================
+ Hits          320     335      +15     
  Misses         10      10
Impacted Files Coverage Δ
fs/sshfs/sshfs.py 95.9% <100%> (+0.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c738064...4a15def. Read the comment docs.

fs/sshfs/sshfs.py Outdated Show resolved Hide resolved
fs/sshfs/sshfs.py Outdated Show resolved Hide resolved
fs/sshfs/sshfs.py Outdated Show resolved Hide resolved
@althonos
Copy link
Owner

You can run the tests locally if you have the Docker client installed and running, and the docker Python package available as well, with python setup.py test. Otherwise just check the Travis-CI output (the integration is fucked up so it's not reporting as a check anymore but PRs are still being built).

@jwnimmer-tri
Copy link
Contributor Author

Thanks! I was able to get the tests running locally.

FYI I'll squash the new commits down again once the reviews are complete -- I'm worried that github reviews will not show things clearly otherwise; I don't have much experience with its workflow. (I use https://reviewable.io/ for all of my reviews, and it's astonishingly great.)

@althonos
Copy link
Owner

No problem, in the end I'll just squash everything in one commit so feel free to make your branch dirty 😉

@jwnimmer-tri
Copy link
Contributor Author

@althonos All of my changes are pushed; do you have any additional feedback?

start, stop = page or (None, None)
try:
with convert_sshfs_errors('scandir', path, directory=True):
stat_iter = self._sftp.listdir_iter(_path)
Copy link
Owner

Choose a reason for hiding this comment

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

Just use listdir_attr here, this way you won't have to collect the results with list later!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I was trying to preserve the responsiveness benefits of listdir_iter while paging, but maybe nobody uses paging with sshfs anyway, since we don't have a fast way to skip to the start.

@althonos
Copy link
Owner

Thanks again! I'll merge and then tinker with the code a bit to see if I can resolve the concurrency issues by locking during iteration using a custom iterator.

@althonos althonos merged commit 34dd7bd into althonos:master Nov 27, 2019
@althonos
Copy link
Owner

I released the patch in v0.12.2 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improving the throughput of scandir
2 participants