Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: JRuby 1.6.5, JRuby 1.7.0.pre1
-
Fix Version/s: None
-
Component/s: Core Classes/Modules
-
Labels:None
-
Number of attachments :
Description
Edit by CON: This bug was originally reported against IOInputStream, but after inspection it seems to be a perf regression in File.new/File.open instead.
The following code
@JRubyMethod(meta = true)
public static IRubyObject test(ThreadContext ctx, IRubyObject recv, IRubyObject value) {
try {
Ruby rt = ctx.getRuntime();
InputStream in = new IOInputStream(value);
byte[] buf = new byte[8192];
int read;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((read = in.read(buf)) != -1)
{ baos.write(buf, 0, read); } return rt.newString(new ByteList(baos.toByteArray(), false));
} catch(Exception e)
}
runs noticeably slower in JRuby trunk than on JRuby 1.6.5.1. Here's my
benchmarks:
$ jruby -v
jruby 1.7.0.dev (ruby-1.8.7-p357) (2012-01-21 0d0c764) (Java HotSpot(TM) 64-Bit Server VM 1.7.0_02) [linux-amd64-java]
$ jruby --1.9 -Ilib test/scratch.rb
user system total real
File.new 8.331000 0.000000 8.331000 ( 8.331000)
File.open 6.291000 0.000000 6.291000 ( 6.291000)
File.open(..., 'rb') 6.502000 0.000000 6.502000 ( 6.502000)
$ jruby -v
jruby 1.6.5.1 (ruby-1.8.7-p330) (2011-12-27 1bf37c2) (Java HotSpot(TM) 64-Bit Server VM 1.7.0_02) [linux-amd64-java]
$ jruby --1.9 -Ilib test/scratch.rb
user system total real
File.new 6.802000 0.000000 6.802000 ( 6.801000)
File.open 5.253000 0.000000 5.253000 ( 5.253000)
File.open(..., 'rb') 5.145000 0.000000 5.145000 ( 5.146000)
where the IO object was created using
File.new(File.expand_path("certificate.cer", File.dirname(_FILE_)))
File.open(File.expand_path("certificate.cer", File.dirname(_FILE_)))
File.open(File.expand_path("certificate.cer", File.dirname(_FILE_)), "rb")
for the corresponding lines.
I also attached the "certificate.cer". Due to the small size of the file,
IOInputStream#read is essentially only called twice in the while
loop.
One thought: Looks like in commit 8ca2281b9c741c6f4f8462cf0d556eab7624143b we started checking respond_to("read") every time before we do a read operation. We should only be doing that if it's not a RubyIO and doesn't have a custom version of read, though. Investigating.