Common Lisp: Does `load` do `compile-file` things?
Asked Answered
F

1

6

Suppose I have a file named "includes.cl", inside which there are several function definitions. Now I have two ways to use these functions:

  1. (load "includes.cl")
  2. (load (compile-file "includes.cl"))

Is the latter faster than the former? I only concern the runtime speed of function invoking.

Fassett answered 8/9, 2013 at 2:56 Comment(2)
what does the Lisp spec or the implementation manuals say? LOAD is not COMPILE-FILE and does not call COMPILE-FILE.Acromion
@RainerJoswig So the former is slower than the latter during runtime execution?Fassett
T
5

To answer the question you ask, there is no way to say a priori which of your two forms is faster. However, your second form will probably result in the functions and macros found in "includes.cl" being executed faster.

More to the point though, just like you would not recompile a C library every time you link something against it, you should not recompile a Lisp library before every load.

At the very least you should be using something like load-compile-maybe or a Lisp analogue of make, such as asdf.

EDIT: you are using SBCL which does not have an interpreter, only a compiler. This means that all code is compiled before is it executed, so the two forms in your question are equivalent. However, the bulk of the cost is in compile-file, not in load, so it is a very good idea to compile the file once and then load it using (load "includes") (note the lack of file type, AKA, extension).

Torrefy answered 8/9, 2013 at 6:3 Comment(2)
I have tried some experiments, and the results show that the execution times are the same for (load "includes.cl") and (load (compile-file "includes.cl")). Why? I use SBCL.Fassett
Because the compiled version is already processed thus loads faster, but that win is eaten by compile-file. Basically, in SBCL, load of a source is the same as load+compile-file.Torrefy

© 2022 - 2024 — McMap. All rights reserved.