-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
Simple File IO is slower in JRuby 9.x than 1.7.x #4681
Comments
Almost looks like some buffering went away to get that much slower. |
@alobmaier @enebo I can't reproduce any issue with the current I see the following from this code: ➜ bench git:(4681) ✗ jruby -v bench_io.rb
jruby 1.7.26 (1.9.3p551) 2016-08-26 69763b8 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_131-b11 +jit [darwin-x86_64]
user system total real
0.590000 0.070000 0.660000 ( 0.225000)
0.180000 0.070000 0.250000 ( 0.213000)
0.200000 0.070000 0.270000 ( 0.209000)
0.130000 0.070000 0.200000 ( 0.198000)
0.170000 0.070000 0.240000 ( 0.204000)
looks like we even got a little faster? |
@original-brownbear Windows is not fully native like MacOS/Linux are for IO so I am betting this is still an issue on windows. |
@enebo ah right my bad, forget I said anything :) |
Still a problem with JRuby 9.2.8 (on master). I'm pretty sure this relates to how we handle text mode, but I'll poke at it for a few minutes. |
Yep, confirmed. Because we can't specify O_TEXT at the file-opening level on Windows. Our workaround for that installs a transcoding stage that handles the newlines as a separate transcoding pass, which is likely why this is many times faster when specifying binary mode (binary mode does not do crlf translation):
These binary read numbers are also significantly faster than JRuby 1.7.27:
|
Here's interleaved text and binary mode numbers:
|
Ok so we're not going to get to this in 9.2.8. I am filling in what information we have so we can do this for 9.2.9. Basically the problem here is that Java IO provides no way to set O_TEXT when opening a file, forcing us to do all our own CRLF translation using the transcoding subsystem. That is much slower than allowing Windows do to the translation for us. However as of 9.2.8 we have incorporated code (from #5809 and related issues) that allows us to dig out a file descriptor from Windows IO channels. This combined with the @byteit101 This may be something you are interested in playing with? Basically we have a number of places in our ported IO logic where I've commented out O_BINARY or O_TEXT logic; other locations may have been deleted, but we can audit the MRI code and see where they do these sets. If we're able to access the real file descriptor and set these flags, we can remove the logic that forces manual CRLF translation. Commented code: jruby/core/src/main/java/org/jruby/RubyIO.java Lines 552 to 561 in 50afda4
jruby/core/src/main/java/org/jruby/RubyIO.java Lines 264 to 268 in 50afda4
jruby/core/src/main/java/org/jruby/RubyIO.java Lines 3090 to 3103 in 50afda4
jruby/core/src/main/java/org/jruby/RubyIO.java Lines 4167 to 4187 in 50afda4
jruby/core/src/main/java/org/jruby/util/io/OpenFile.java Lines 2120 to 2129 in 50afda4
Forced CRLF transcoding: jruby/core/src/main/java/org/jruby/util/io/OpenFile.java Lines 913 to 929 in 50afda4
|
FWIW if you are reading text files you know do not contain CRLF line terminators, you can just tell it to use binary mode (using |
Hmm, possibly. Of note: getting the real fd for |
Given the cost of manually doing CRLF translation, I think the cost of additional handles/descriptors is tolerable. |
Detargeting. This could happen any time, but someone needs to sit down on Windows and make native IO work. |
When doing a simple benchmark for file IO (reading a big text file several times), I encountered a performance regression.
Used text file: test.txt
Benchmark code:
Environment
Running on Windows 10 (Version 1607).
Expected Behavior
I expected at least the same performance than JRuby 1.7.26.
Actual Behavior
JRuby 1.7.26:
C:\code> jruby -v .\io.rb jruby 1.7.26 (1.9.3p551) 2016-08-26 69763b8 on Java HotSpot(TM) Client VM 1.8.0_111-b14 +jit [Windows 10-x86] user system total real 1.466000 0.000000 1.466000 ( 1.466000) 1.332000 0.000000 1.332000 ( 1.331000) 0.887000 0.000000 0.887000 ( 0.887000) 1.108000 0.000000 1.108000 ( 1.108000) 1.301000 0.000000 1.301000 ( 1.301000)
JRuby 9.1.10.0:
C:\code> jruby -v .\io.rb jruby 9.1.10.0 (2.3.3) 2017-05-25 b09c48a Java HotSpot(TM) Client VM 25.111-b14 on 1.8.0_111-b14 +jit [mswin32-x86] user system total real 19.523000 0.000000 19.523000 ( 19.522826) 21.285000 0.000000 21.285000 ( 21.284657) 20.799000 0.000000 20.799000 ( 20.799130) 19.675000 0.000000 19.675000 ( 19.675062) 19.823000 0.000000 19.823000 ( 19.823282)
The text was updated successfully, but these errors were encountered: