Project

General

Profile

Actions

Bug #2742

closed

IO#read/gets can be very slow in doze

Added by rogerdpack (Roger Pack) about 14 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2dev (2010-02-12 trunk 26649) [i386-mingw32]
Backport:
[ruby-core:28162]

Description

=begin
this code

n = 100 * 1000 * 1000
puts "writing"
File.open("foo", 'wb'){|f| f.write(" " * n) }
puts "reading"
File.open("foo", 'r') do |io|
io.read
end

takes something like 700s in windows, most of the time is spent in rb_str_resize. Cause seems to be that it is rb_str_resize'ing the string by 1024B at a time, so N^2 in the amount of time it takes to read it in because it has to keep copying it to the newly sized string.

The same thing happens for

File.open("foo", 'rb') do |io|
io.gets
end

except that it reads (and resizes) in 8K bytes. Not sure why they're different sizes. I'd imagine this problem exists in Linux, but without as much of a negative impact as it reads in larger sizes.
=end


Related issues 2 (0 open2 closed)

Related to Backport187 - Backport #2741: gets with large file is slow in windozeClosedActions
Related to Ruby master - Bug #1332: Reading file on Windows is 500x slower then with previous Ruby versionClosedakr (Akira Tanaka)03/30/2009Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0