Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #552 (closed defect: fixed)

Opened 17 years ago

Last modified 17 years ago

Buffer + FileConduit = VERY SLOW on Windows

Reported by: CyberShadow Assigned to: kris
Priority: normal Milestone: 1.0
Component: IO Version: trunk
Keywords: Cc: thecybershadow@gmail.com

Description

The following program:

import tango.io.Buffer;
import tango.io.FileConduit;
import tango.io.Print;
import tango.text.convert.Layout;

void main()
{
	auto layout = new Layout!(char);
	FileConduit outputConduit = new FileConduit("test.txt", FileConduit.ReadWriteCreate);
	auto buffer = new Buffer(outputConduit); auto output = new Print!(char) (layout, buffer);

	for(int i=0;i<1000;i++)
		output(i).newline;

	buffer.flush();
	outputConduit.close;
}

takes 22 seconds to run on my Windows machine.

I suspect that the reason for it is that Print.newline() flushes the underlying buffer, which causes it to flush the underlying conduit, which forces the OS to flush the file. Of course, that's overkill when writing text files - but it's a valid point that flushing is needed when writing to the screen. Therefore, I suggest the following:

  • OutputStream?.flush() and IBuffer.flush() to be changed to flush(bool recursive=true) - the "recursive" parameter dictates whether it should flush any underlying components
  • code that doesn't require that all underlying components to be flushed, such as the Print class, should call .flush(false)

The workaround I use is printing things to a GrowBuffer? (which was broken without the two patches I submitted earlier).

Change History

07/31/07 20:03:35 changed by kris

have you tried this by chance?

for(int i=0;i<1000;i++)
    output(i)('\n');

07/31/07 20:19:25 changed by CyberShadow

Ah yes, of course, that didn't occur to me at the time of writing the code and filing this ticket. Since it's a fairly important issue, I'd like to ask:

  • can we expect Tango not to call .newline internally where flushing isn't appropriate?
  • is there a cross-platform way to get/write the line ending character? (Print.Eol is a private constant)
  • is there a simple, readable way to write a line (string with EOL terminator) that doesn't involve control characters, like Phobos's writefln?

07/31/07 21:03:55 changed by kris

  • status changed from new to assigned.

we've been trying to avoid the issues inherent in the C lib regarding flushing, redirection, and a handful of funky corner cases. Right now, flush is 'dumb' while we figure out just how to handle it appropriately.

Print.Eol may get exposed, if we don't find a better way to do that.

I think there's a Print.formatln ?

07/31/07 23:04:04 changed by kris

checkin [2474] is a tentative resolution for the newline issue. Just use newline() rather than '\n' or whatever ...

08/16/07 23:38:55 changed by kris

  • status changed from assigned to closed.
  • resolution set to fixed.