This is the mail archive of the guile@sourceware.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]

Guile loading speed: What a little function can do...


The major reason for Guile's slow loading speed has always been the
fact that a chain of Scheme level procedures has been evaluated for
every top-level symbol lookup during the first pass through the code.

I've suggested a simple kludge to fix this and have repeated the
argument at many occasions during the years when the discussion has
returned.  Personally, I've never been bothered by Guile's slow
loading speed, so I thought I would let someone else do it...

After four years, I conclude that "someone else" is a lazy bastard who
is perfectly willing to spend 100 times the energy *discussing* the
problem than the energy required to write the following function.  ;-)

static SCM
module_variable (SCM module, SCM sym)
{
  /* 1. Check module obarray */
  SCM b = scm_hashq_ref (OBARRAY (module), sym, SCM_UNDEFINED);
  if (SCM_VARIABLEP (b))
    return b;
  {
    SCM binder = BINDER (module);
    if (SCM_NFALSEP (binder))
      /* 2. Custom binder */
      {
	b = scm_apply (binder,
		       SCM_LIST3 (module, sym, SCM_BOOL_F),
		       SCM_EOL);
	if (SCM_NFALSEP (b))
	  return b;
      }
  }
  {
    /* 3. Search the use list */
    SCM uses = USES (module);
    while (SCM_CONSP (uses))
      {
	b = module_variable (SCM_CAR (uses), sym);
	if (SCM_NFALSEP (b))
	  return b;
	uses = SCM_CDR (uses);
      }
    return SCM_BOOL_F;
  }
}

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