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

In the _isDir function, set the max_items=1 when _lsdir #946

Open
zhouaoe opened this issue Mar 7, 2025 · 2 comments
Open

In the _isDir function, set the max_items=1 when _lsdir #946

zhouaoe opened this issue Mar 7, 2025 · 2 comments

Comments

@zhouaoe
Copy link

zhouaoe commented Mar 7, 2025

In the _isdir function, the _lsdir function is used to determine whether a directory exists, but max_items is not set. This results in a default listing of 1000 items, whereas only one item is actually needed to verify the existence of the directory.

s3fs is widely used on many object storage systems that are compatible with the S3 protocol. For example, some users use s3fs to access Aliyun OSS services; in this case, limiting max_items can bring significant performance improvements.

Of course, here we need to be mindful of the impact on dircache. The result carrying max_items is incomplete. However, when there is an especially large number of files, such as in AI training datasets, the cost of listing the directory every time to check if a directory exists becomes prohibitively expensive. It is sufficient to update the dircache only when the user explicitly performs an ls.

@martindurant
Copy link
Member

You suggestion is reasonable, and I would accept a PR. However, be aware that there is one downside: for a complete directory listing, we cache the return making subsequent isdir or listing operations much faster. However, you have convinced me that when a user explicitly wants isdir, they probably won't be calling that multiple times.

@zhouaoe
Copy link
Author

zhouaoe commented Mar 10, 2025

Thank you for your reply, and I will submit a PR later.

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

No branches or pull requests

2 participants