Bug #1544: rb_io_write bug? http://redmine.ruby-lang.org/issues/show/1544 Author: Brian Lopez Status: Open, Priority: Normal ruby -v: ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-darwin9.6.0] I'm using rb_io_write to write (in C) to a StringIO instance (which was defined in Ruby, and passed to my C code) and noticed some strange behavior. I'm writing to the IO at the beginning of a recursively called method and under 1.9.1 it's *really* slow unless I buffer up the contents then only write to the IO once using rb_io_write. For what I'm doing it's the difference between completing in 3.3 seconds, vs 0.13 seconds. Under 1.8.6 I can write to the IO using rb_io_write in the smaller chunks (on ever recursive call) and it performs similar to the buffered write in 1.9.1. Any known reason for this?
on 30.05.2009 22:34
on 31.05.2009 22:44
Hi,
In message "Re: [ruby-core:23642] [Bug #1544] rb_io_write bug?"
on Sun, 31 May 2009 05:33:18 +0900, Brian Lopez
<redmine@ruby-lang.org> writes:
|I'm using rb_io_write to write (in C) to a StringIO instance (which was defined in Ruby, and passed to my C code) and noticed some strange behavior.
|I'm writing to the IO at the beginning of a recursively called method and under 1.9.1 it's *really* slow unless I buffer up the contents then only write to the IO once using rb_io_write. For what I'm doing it's the difference between completing in 3.3 seconds, vs 0.13 seconds.
|Under 1.8.6 I can write to the IO using rb_io_write in the smaller chunks (on ever recursive call) and it performs similar to the buffered write in 1.9.1.
1.9 does not use stdio, so there's possibility.
Can you show us the code to profile?
matz.
on 30.06.2009 01:26
Issue #1544 has been updated by Brian Lopez. Sorry, I didn't have this ticket on "watch" and didn't notice you'd replied already... Anyway, the code is in my yajl-ruby project. Specifically, if you look here: http://github.com/brianmario/yajl-ruby/blob/866e58ed553083e079ed5797eb5a6256dd6ce2d3/ext/yajl_ext.c#L74 That line is the call to rb_io_write that I was talking about. You'll notice I have it only call rb_io_write if the write buffer size is equal or surpassed the WRITE_BUFSIZE constants value (defaults to 8kb). Previously, I wasn't doing that buffer size check and just calling rb_io_write on every call of the yajl_encode_part function (which is called recursively. That's how I surfaced the issue. Again, it's performant in 1.8.6 either way (with the buffer size check or without). ---------------------------------------- http://redmine.ruby-lang.org/issues/show/1544
on 27.01.2010 02:04
Issue #1544 has been updated by Roger Pack. Can you extract a small reproducible script? -r ---------------------------------------- http://redmine.ruby-lang.org/issues/show/1544