Shen-Language / shen-cl

Shen for Common Lisp (Unmaintained)
BSD 3-Clause "New" or "Revised" License
122 stars 11 forks source link

Integrate "factorise-defun" extension #41

Closed tizoc closed 5 years ago

tizoc commented 5 years ago

It is enabled for user code, but the kernel itself is not compiled with this optimization enabled.

It is complicated because the kernel has to compile itself, and the extension relies on having Shen loaded for some stuff. Since the boot process compiles itself as it goes there is a chicken/egg problem here.

Switching to Shen/Scheme's model, where a full external Shen is used to build it could solve this problem, but maybe better left for later (if Shen/Scheme's compiler gets ported here, then the solution comes with it).

Running the Shen test suite takes the same amount of time with factorisation enabled or disabled (basically same as in Shen/Scheme, what is important is that it is not slower).

Times for the same functions I used to test this in Shen/Scheme:

simplify regular 
Evaluation took:
  3.864 seconds of real time
  3.845448 seconds of total run time (3.791698 user, 0.053750 system)
  [ Run times consist of 0.024 seconds GC time, and 3.822 seconds non-GC time. ]
  99.51% CPU
  9,272,407,653 processor cycles
  2,240,019,872 bytes consed

simplify optimized 
Evaluation took:
  3.431 seconds of real time
  3.415437 seconds of total run time (3.393865 user, 0.021572 system)
  [ Run times consist of 0.023 seconds GC time, and 3.393 seconds non-GC time. ]
  99.53% CPU
  8,231,804,550 processor cycles
  2,240,001,680 bytes consed

neal regular 
Evaluation took:
  4.307 seconds of real time
  4.290840 seconds of total run time (4.276924 user, 0.013916 system)
  [ Run times consist of 0.002 seconds GC time, and 4.289 seconds non-GC time. ]
  99.63% CPU
  10,336,071,522 processor cycles
  320,012,288 bytes consed

neal optimized 
Evaluation took:
  3.137 seconds of real time
  3.125138 seconds of total run time (3.115084 user, 0.010054 system)
  [ Run times consist of 0.002 seconds GC time, and 3.124 seconds non-GC time. ]
  99.62% CPU
  7,527,416,121 processor cycles
  320,006,912 bytes consed
tizoc commented 5 years ago

An interesting detail is that in Common Lisp this saves a bit of allocation (very little)

tizoc commented 5 years ago

Weird that do expressions weren't being compiled into PROGN already, just added that.

tizoc commented 5 years ago

Ok, all seem good, merging.