This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Startup time in guile-1.3 (II)


Mikael Djurfeldt <mdj@nada.kth.se> writes:

> So, we have to look for a change between July 21 and now.

OK, found it:

1998-10-09  Jim Blandy  <jimb@zwingli.cygnus.com>

	Do magic to mix reads and writes on stdio FILE-based ports.
	(Thanks to Christian Lynbech.)
	* fports.c (FPORT_READ_SAFE, FPORT_WRITE_SAFE, FPORT_ALL_OKAY):
	New macros.
	(pre_read, pre_write): New functions.
	(local_fgetc, local_fgets, local_ffwrite, local_fputc,
	local_fputs): Call them.
	(local_fflush): Mark the port as ready for reading and writing.
	(scm_stdio_to_port): Set the FPORT_READ_SAFE, FPORT_WRITE_SAFE
	flags on new port objects.  This might not be accurate --- who
	knows what state the FILE * is in when we get it --- but it won't
	do extraneous calls to fflush or fseek, so it's no worse than the
	behavior before this change.

This is how the new code looks like:

static inline void
pre_read (SCM port)
{
  if (! (SCM_CAR (port) & FPORT_READ_SAFE))
    fflush ((FILE *)SCM_STREAM (port));

  /* We've done the flush, so reading is safe.
     Assuming that we're going to do a read next, writing will not be
     safe by the time we're done.  */
  SCM_SETOR_CAR  (port,  FPORT_READ_SAFE);
  SCM_SETAND_CAR (port, ~FPORT_WRITE_SAFE);
  
}

static int
local_fgetc (SCM port)
{
  FILE *s = (FILE *) SCM_STREAM (port);
  pre_read (port);
  if (feof (s))
    return EOF;
  else
    return fgetc (s);
}

This is how the code *should* look like:

static int
local_fgetc (SCM port)
{
  return fgetc ((FILE *) SCM_STREAM (port));
}

The former gives a startup speed of 4.68 on my Ultra.
The latter gives 0.86 s.

I actually got angry when I saw this change.  It's completely insane
to do that much work for every character being read in the innermost
loop of the reader.

Doesn't people have any feeling for what is time critical and what is
not?

/mdj