File Performance Q.?

Andreas Raab Andreas.Raab at gmx.de
Sat May 11 16:38:31 UTC 2002


David,

> > If Squeak had buffered file io in the smalltalk layer this type of 
> > test would of course run faster.
> 
> I wonder if that's actually the case. Most of the Squeak VMs are using
> the stdio library for file IO, which is already buffered, and which on
> many platforms is already making use of an OS buffer cache.  Adding
> another layer of buffering in Smalltalk might just slow things down.

Squeak's internal stream primitives are a _hell_ of a lot faster than
going through the various layers of external code. It's actually simple
to try out:

"using the OS buffering for files"
t1 := [fs := FileStream readOnlyFileNamed: Smalltalk changesName.
	[fs next == nil] whileFalse.
	fs close] timeToRun.

"using internal buffering"
t2 := [fs := FileStream readOnlyFileNamed: Smalltalk changesName.
	[fs atEnd] whileFalse:[
		cached := ReadStream on: (fs next: 4096).
		[cached next == nil] whileFalse.
	].
	fs close] timeToRun.

When I ran a few benchmarks I always came up with at least a factor of
two in advantage of internal buffering even if the OS does file
buffering. Of course, if you have large read operations (starting
somewhere around 1/4 buffer size) you should go straight to the file
system but for small reads internal buffering has huge advantages.

> My completely untested speculation is that adding IO buffering in the
> image would be useful for Squeak NOS, but not much else.

See above. Try it on your favourite platform to see how it behaves.

Cheers,
  - Andreas




More information about the Squeak-dev mailing list