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

Speed up SAF 100x #372

Merged
merged 3 commits into from
Oct 5, 2024
Merged

Speed up SAF 100x #372

merged 3 commits into from
Oct 5, 2024

Conversation

lmagyar
Copy link
Contributor

@lmagyar lmagyar commented Sep 3, 2024

Summary:

  • When there are 1000s of files in a dir, even opening a file takes several minutes!!!
  • The root cause is that creating even 1 SafFile involves a call to DocumentFile.findFile() and it calls listFiles(), and that is extremely slow on a big dir.
  • I've copied the Cursor code from RoSafFileSystemView.getFile() (with some minor improvements).
  • Now opening a file is a fraction of a second on a dir with 1000s of files!!!
  • Though listing a dir is still slow, it uses listFiles(), and we can't do anything about it.

One issue with the code below:

  • When there is an invalid path, like /valid-folder/nonexistent-folder/nonexistent-folder/file.xxx, what should we do with nonexistent-folders???
  • We should throw an Exception, but this is not allowed here, we can't return null, it will harm SftpSubsystem.
  • Original code returned a SafFile referencing /valid-folder/invalid-folder and finally a file was created with the name of invalid-folder, still not a good outcome. And without any error message.

UPDATE: this PR can remain as is, this issue will be fixed in a new PR, because it got quite complex

Possible better solutions:
- Extend FileSystemView.getFile() with a throws Exception and modify SftpSubsystem's code? I remember you don't like modifying the original server's code.
- Create some dummy "fails on everything" SafFile+SafFtpFile+SafSshFile, and that will throw the proper FileNotFoundException on the first call? Maybe this is the most analog to what would happen on a real file-system with File. But it smells like an ugly hack.
- Any idea???

@lmagyar lmagyar mentioned this pull request Sep 3, 2024
@wolpi
Copy link
Owner

wolpi commented Sep 7, 2024

That sounds quite good 🤩
I've to take a deeper look, also together with the other PRs.

@lmagyar
Copy link
Contributor Author

lmagyar commented Sep 28, 2024

After seeing #205, I will experiment with the non-existent-path problem. Until it is done, I mark this as draft.

In case of plain old file-system, this is not an issue to create a file without creating a new folder, FsFile has a workaround for this here.

We should do something like FsFile in SafFile/RoSafFile, but it is hard, SafFile requires an existing parentDocument, and in this case it is nonexistent. More investigation is needed.

@lmagyar lmagyar marked this pull request as draft September 28, 2024 17:58
@lmagyar lmagyar changed the title Speed up SAF 100x WIP: Speed up SAF 100x Sep 28, 2024
@lmagyar
Copy link
Contributor Author

lmagyar commented Sep 29, 2024

Without change, it's ready for review again.

This PR can remain as is, the "file under nonexistent folder issue" will be fixed in a new PR, because it got quite complex.

@lmagyar lmagyar changed the title WIP: Speed up SAF 100x Speed up SAF 100x Sep 29, 2024
@lmagyar lmagyar marked this pull request as ready for review September 29, 2024 23:04
@wolpi wolpi merged commit 37ca6b6 into wolpi:master Oct 5, 2024
1 check passed
@wolpi wolpi added this to the 7.3 milestone Oct 5, 2024
@wolpi
Copy link
Owner

wolpi commented Oct 5, 2024

Ok, the trick was to mix those 2 SAF APIs (DocumentFile and URL-based-API). That really improves it. And the changes are not at an end yet 😄

@lmagyar lmagyar deleted the pr-speed-up-saf branch October 5, 2024 18:22
wolpi added a commit that referenced this pull request Oct 19, 2024
…oid calls to listFiles() which is very slow, but use cursor to list children, see GH issues #372 and #376
lmagyar pushed a commit to lmagyar/prim-ftpd that referenced this pull request Oct 19, 2024
…oid calls to listFiles() which is very slow, but use cursor to list children, see GH issues wolpi#372 and wolpi#376
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.

2 participants