Menu

#2845 Avoid initialization-time compile in commac.lisp

None
closed
nobody
5
2018-04-21
2014-11-20
Nils Bruin
No

When running maxima 5.34.1 on ecl I get:

$ maxima
;;; Loading #P"/usr/local/sage/sage-git/local/lib/ecl/cmp.fas"
;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3, Debug=0
;;;
;;; End of Pass 1.
;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3, Debug=0
;;;
;;; End of Pass 1.
;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3, Debug=0
;;;
;;; End of Pass 1.
;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3, Debug=0
;;;
;;; End of Pass 1.
;;; Loading #P"/usr/local/sage/sage-git/local/lib/ecl/sb-bsd-sockets.fas"
;;; Loading #P"/usr/local/sage/sage-git/local/lib/ecl/sockets.fas"
;;; Loading #P"/usr/local/sage/sage-git/local/lib/ecl/defsystem.fas"
Maxima 5.34.1 http://maxima.sourceforge.net
using Lisp ECL 13.5.1
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1)

There comments indicate that the compiler is run 4 times upon initialization time. It would be a lot cleaner if the compiling work would already be done at compile time (and given ECLs architecture, it would make distributing ecl-based maxima easier, since compiling on ECL requires a working, compatible C compiler to be present). The offending lines are in commac.lisp:

(defparameter trailing-zeros-regex-f-0 (compile nil (maxima-nregex::regex-compile "^(.*\\.[0-9]*[1-9])00*$")))
(defparameter trailing-zeros-regex-f-1 (compile nil (maxima-nregex::regex-compile "^(.*\\.0)00*$")))
(defparameter trailing-zeros-regex-e-0 (compile nil (maxima-nregex::regex-compile "^(.*\\.[0-9]*[1-9])00*([^0-9][+-][0-9]*)$")))
(defparameter trailing-zeros-regex-e-1 (compile nil (maxima-nregex::regex-compile "^(.*\\.0)00*([^0-9][+-][0-9]*)$")))

If the maxima-nregex code really does need compiling, can we rewrite this to run at compile time (and then bind it to the parameters later)? An alternative would be to just not compile it: by the time you're looking at string representations of floats, you're not exactly aiming for high performance.

Discussion

  • Robert Dodier

    Robert Dodier - 2014-11-24
    • labels: --> ECL, installation, build, regular expressions, float formatting
    • status: open --> closed
     
  • Robert Dodier

    Robert Dodier - 2014-11-24

    Fixed by commit 9a450c2a3. Closing this report.

    For the record, ECL can't serialize a compiled function (didn't try any other Lisps) so compiling at build time didn't work; I tried #.(compiled stuff). I didn't try any other scheme to compile those expressions at build time.

     
  • Nils Bruin

    Nils Bruin - 2014-11-26

    ECL can't serialize a compiled function

    I think the fix here is adequate, so no need to reopen the ticket, but I doubt your assessment is correct:

    Whenever you compile a function and save the "fas"/"fasl" the compiled function is "serialized". I would expect the solution to be along the lines of

    (defun trailing-zeros-regex-f-0-function (...)
        <body generated by maxima-nregex::regex-compile> )
    

    You could basically do this by pasting the generated body right into the defun manually, so I'm sure that with some macro-magic you can make lisp do that for you, provided that maxima-nregex:regex-compile is available for running at compile-time for commac.lisp.

    It seems that something along the lines of

    (defun call-regex-generated-function (s)
         (funcall #.(maxima-nregex::regex-compile "^(.*\\.[0-9]*[1-9])00*$") s))
    

    seems to work and if you'd put that in commac.lisp, wouldn't you just end up with a compiled version? (a good compiler would ensure any overhead of the funcall would disappear)

    Indeed, I have tried. If you place the defun above in a file, say "ctest.lisp" and then compile it:

    > (require `maxima)
    > (compile-file "ctest.lisp")
    

    then indeed, the file gets properly compiled into a "fas" (I have checked the generated c code, and I do not see any reference there to regex-compile, so I'm pretty sure the expanded code got compiled). Of course, the trick is that you need to ensure that maxima-nregex::regex-compile is available for execution at compile time, but I suspect you already got that bit.

     

    Last edit: Nils Bruin 2014-11-27
  • Robert Dodier

    Robert Dodier - 2018-04-21

    I've (finally) accepted the merge request: https://sourceforge.net/p/maxima/code/merge-requests/1/

    Sorry for the delay! I appreciate your help. I didn't see the merge request sitting there ... an oversight on my part which I hope you'll forgive. Better late than never, I hope.

     

Log in to post a comment.

MongoDB Logo MongoDB