-
Notifications
You must be signed in to change notification settings - Fork 117
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
[FS] Speed-up LocalFile.copy() by using Java-NIO's Files.copy() #1471
[FS] Speed-up LocalFile.copy() by using Java-NIO's Files.copy() #1471
Conversation
An example of possible speed-ups can be found in https://bugs.eclipse.org/bugs/show_bug.cgi?id=577432. The exact values of course depend on the actual hard-drive and the size of the file(s) copied. |
Thanks @HannesWell for making our ide faster |
If one wants (and the size is known to be large) one can use a Thread that reports some progress regularly using Another alternative would be to observer the target size on the filesystem during the copy operation. |
91957a4
to
6c011dd
Compare
Yes that would be feasible, but actually I would like to avoid that additional complexity. With recent hardware copying even large files is relatively quick. E.g. the actual copy process of my 1GB only took one or two seconds (didn't measure it) and the waiting cursor was visible only for a very short time. Of course not everyone has an SSD but at the same time I don't think that copying such large single files happens that often. But if something like that is implemented, it could also be used for #1475. But if the file-size is not known, it is not very useful to report anything for the sake of reporting something. As far as I know, to relax nervous users the progress par is already animated to give the impression of progress even if nothing is reported. |
6c011dd
to
1a9af68
Compare
So what's the opinion of the other committers about this (and #1475)? Monitoring the size of the target file would add quite a bit of complexity and would also not be possible in all cases of #1475 since for example we don't know the exact length of the content that can be read from the If we agree to have this I suggest to submit this in time before M2 on Friday. |
I haven't had time to read the patch, but I would be fine with that above. |
Yes, faster is more important |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with the proposed change as well, both from the conceptual as well as the technical side. I only have a minor comment regarding error generation.
...es/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java
Outdated
Show resolved
Hide resolved
1a9af68
to
fcd86c9
Compare
Thank you all for your positive feedback. If there are no objections in the meantime, I plan to submit this and #1475 this (European) evening. Then we have it in time for M2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on these improvement, Hannes!
...les/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/messages.properties
Outdated
Show resolved
Hide resolved
Using Files.copy() can be significantly faster than reading the content from a source InputStream and writing it to a target OutputStream. The only drawback of using using Files.copy() is that continuous progress reporting during the copy operation is not possible. For small files (which are copied in short time) this is not really a relevant and for large files the performance gain outweighs the loss of fine-grained progress information.
fcd86c9
to
86c92ed
Compare
@HannesWell Please prove it is faster for small files or revert. I tried the same "optimization" multiple times in the past years (last example #1452 (comment)) and i always had to conclude by measurements that Files.copy() was slower on windows. |
It would have been more useful if you would provide more details about your benchmarks. Otherwise it's just a statement nobody can discuss. As you probably know, statements about performance are often not absolute and usually context depended. For example for small files I can indeed reproduce that
From looking into the JDK code, I assume this is probably because I have now spend more time on this and created a very simple benchmark that uses the code below in the displayed variations(I know there are many uncertainties in it and one should use JMH. So the numbers have probably quite some errors!) :
These are the numbers I get for the tested scenarios for different file-sizes (Reminder: the times probably have a relatively large error):
In Java-21 |
I think we have two options here:
Maybe the latter is more performant even for small files since we save the source/target attribute read (has to be checked), but it is more work and I don't think I have the time to land that for the upcoming release. |
i used a jmh benchmark:
I doubt that copying a 1GB file is the standard usecase that we should optimize for. Based on the workspaces i know, resources rather have a typical size for 5kb to 500kb. However as you can see in my benchmark result the copy time does only slightly depend of the actual file size in that range. It's a fast memory copy only anyway, while opening the file in the filesystem is the most costly thing on my computer. Option 3: just revert your changes. |
Smaller files are probably copied way more often.
In general there are really a lot of variables that make it hard to make solid statements about the performance of file-IO and its relations. There are just too many factors. Does one use a hard-disk drives, a S-ATA SSD or an NVMe SSDs? With OS and which file-stystem is used. E.g. on Windows also activity of antivirus software or the Windows the Search-Index can temporarily slow down IO operations drastically (can make bench-marking a challenge).
That's an option, but I would be in favor of one that gives us the best for both cases: I'll later provide a follow-up with an implementation that calls native copy methods. But it's something for the next release cycle to complete it. |
Using
Files.copy()
can be significantly faster than reading the content from a sourceInputStream
and writing it to a targetOutputStream
.The only drawback of using using Files.copy() is that continuous progress reporting during the copy operation is not possible. For small files (which are copied in short time) this is not really a relevant and for large files the performance gain outweighs the loss in progress information.