Github messages for voidlinux
 help / color / mirror / Atom feed
* [ISSUE] maxima (sbcl) arithmetic is very slow
@ 2022-01-04 19:19 tornaria
  2022-01-04 19:47 ` tornaria
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: tornaria @ 2022-01-04 19:19 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1979 bytes --]

New issue by tornaria on void-packages repository

https://github.com/void-linux/void-packages/issues/34849

Description:
Maybe coming from slow arithmetic in sbcl:
```
$ rmaxima
Maxima 5.45.1 https://maxima.sourceforge.io
using Lisp SBCL 2.1.10
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) showtime : true $
Evaluation took 0.0001 seconds (0.0000 elapsed) using 0 bytes.
(%i2) a : 10^(10^5) $
Evaluation took 0.0192 seconds (0.0200 elapsed) using 96.047 KB.
(%i3) b : a^10 $
Evaluation took 1.1198 seconds (1.1194 elapsed) using 1023.875 KB.
(%i4) b : a^20 $
Evaluation took 4.5570 seconds (4.5607 elapsed) using 2.147 MB.
(%i5) 
```

Contrast with maxima-ecl:
```
$ rmaxima -l ecl
;;; Loading #P"/usr/lib64/ecl-21.2.1/sb-bsd-sockets.fas"
;;; Loading #P"/usr/lib64/ecl-21.2.1/sockets.fas"
Maxima 5.45.1 https://maxima.sourceforge.io
using Lisp ECL 21.2.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) showtime : true $
Evaluation took 0.0000 seconds (0.0000 elapsed)
(%i2) a : 10^(10^5) $
Evaluation took 0.0030 seconds (0.0020 elapsed)
(%i3) b : a^10 $
Evaluation took 0.0420 seconds (0.0440 elapsed)
(%i4) b : a^20 $
Evaluation took 0.0680 seconds (0.0450 elapsed)
(%i5) b : a^40 $
Evaluation took 0.0750 seconds (0.0780 elapsed)
(%i6) b : a^80 $
Evaluation took 0.2420 seconds (0.2000 elapsed)
(%i7) b : a^160 $
Evaluation took 0.4430 seconds (0.3890 elapsed)
(%i8) b : a^320 $
Evaluation took 0.8530 seconds (0.7970 elapsed)
(%i9) b : a^640 $
Evaluation took 1.7850 seconds (1.7040 elapsed)
(%i10) ) b : a^1280 $
Evaluation took 3.7550 seconds (3.6670 elapsed)
(%i11) 
```

Note: ecl compiles with gmp so that's probably where the long arithmetic comes from.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: maxima (sbcl) arithmetic is very slow
  2022-01-04 19:19 [ISSUE] maxima (sbcl) arithmetic is very slow tornaria
@ 2022-01-04 19:47 ` tornaria
  2022-01-04 19:55 ` tornaria
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: tornaria @ 2022-01-04 19:47 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 669 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/issues/34849#issuecomment-1005120770

Comment:
This seems to be due to slow default arithmetic in sbcl:
```
$ sbcl 
This is SBCL 2.2.0, an implementation of ANSI Common Lisp.
[...]
* (* 0 (expt (expt 10 (expt 10 5)) 30))
[takes ~ 10s]
0
```
Now
```
$ sbcl 
This is SBCL 2.2.0, an implementation of ANSI Common Lisp.
[...]
* (require :sb-gmp)
("SB-GMP")
* (sb-gmp:install-gmp-funs)
* (* 0 (expt (expt 10 (expt 10 5)) 30))
[takes < 0.5 s]]
0
```

The solution might be to somehow link maxima to `sb-gmp` and run `(sb-gmp:install-gmp-funs)` at startup.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: maxima (sbcl) arithmetic is very slow
  2022-01-04 19:19 [ISSUE] maxima (sbcl) arithmetic is very slow tornaria
  2022-01-04 19:47 ` tornaria
@ 2022-01-04 19:55 ` tornaria
  2022-01-04 21:16 ` tornaria
  2022-01-11 15:55 ` [ISSUE] [CLOSED] " leahneukirchen
  3 siblings, 0 replies; 5+ messages in thread
From: tornaria @ 2022-01-04 19:55 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1176 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/issues/34849#issuecomment-1005125647

Comment:
Indeed:
```
$ rmaxima 
Maxima 5.45.1 https://maxima.sourceforge.io
using Lisp SBCL 2.2.0
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) :lisp (require :sb-gmp "/usr/lib/sbcl/contrib/sb-gmp.fasl")

(SB-GMP)
(%i1) :lisp (sb-gmp:install-gmp-funs)

(%i1) showtime : true $
Evaluation took 0.0001 seconds (0.0000 elapsed) using 0 bytes.
(%i2) a : 10^(10^5) $
Evaluation took 0.0015 seconds (0.0010 elapsed) using 3.578 KB.
(%i3) b : a^1280 $
Evaluation took 1.5059 seconds (1.5080 elapsed) using 50.689 MB.
(%i4) 
```

Caveats:
 - this only works if `sbcl` is installed (for the file "/usr/lib/sbcl/contrib/sb-gmp.fasl")
 - moreover the version of sbcl used to compile maxima has to match the version of sbcl used to compile `sb-gmp.fasl` (rn maxima was compiled with 2.1.11 but sbcl is at 2.2.0)
 - the "require" statement needs the full path to `sb-gmp.fasl` (not a real problem)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: maxima (sbcl) arithmetic is very slow
  2022-01-04 19:19 [ISSUE] maxima (sbcl) arithmetic is very slow tornaria
  2022-01-04 19:47 ` tornaria
  2022-01-04 19:55 ` tornaria
@ 2022-01-04 21:16 ` tornaria
  2022-01-11 15:55 ` [ISSUE] [CLOSED] " leahneukirchen
  3 siblings, 0 replies; 5+ messages in thread
From: tornaria @ 2022-01-04 21:16 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1483 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/issues/34849#issuecomment-1005176605

Comment:
I had success with the following patch
```
--- a/src/init-cl.lisp	2021-05-15 20:20:53.000000000 -0300
+++ b/src/init-cl.lisp	2022-01-04 17:45:03.838273626 -0300
@@ -574,8 +574,13 @@
 			 (delete-file file)))))
 	   *temp-files-list*))
 
+#+sbcl
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (require 'sb-gmp))
+
 (defun cl-user::run ()
   "Run Maxima in its own package."
+  #+sbcl (sb-gmp:install-gmp-funs)
   (in-package :maxima)
   (initialize-runtime-globals)
   (let ((input-stream *standard-input*)
```
Now maxima is automatically initialized using sb-gmp and arithmetic is fast:
```
$ rmaxima 
Maxima 5.45.1 https://maxima.sourceforge.io
using Lisp SBCL 2.2.0
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) showtime : true $
Evaluation took 0.0001 seconds (0.0000 elapsed) using 0 bytes.
(%i2) a : 10^(10^5) $
Evaluation took 0.0017 seconds (0.0020 elapsed) using 13.516 KB.
(%i3) b : a^1280 $
Evaluation took 1.5245 seconds (1.5270 elapsed) using 50.689 MB.
(%i4) 
```
I want to try to fix an (unrelated) bug with the heap on maxima-ecl  (https://github.com/void-linux/void-packages/pull/34030#issuecomment-1005080267); I'll make a single PR with both.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ISSUE] [CLOSED] maxima (sbcl) arithmetic is very slow
  2022-01-04 19:19 [ISSUE] maxima (sbcl) arithmetic is very slow tornaria
                   ` (2 preceding siblings ...)
  2022-01-04 21:16 ` tornaria
@ 2022-01-11 15:55 ` leahneukirchen
  3 siblings, 0 replies; 5+ messages in thread
From: leahneukirchen @ 2022-01-11 15:55 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1982 bytes --]

Closed issue by tornaria on void-packages repository

https://github.com/void-linux/void-packages/issues/34849

Description:
Maybe coming from slow arithmetic in sbcl:
```
$ rmaxima
Maxima 5.45.1 https://maxima.sourceforge.io
using Lisp SBCL 2.1.10
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) showtime : true $
Evaluation took 0.0001 seconds (0.0000 elapsed) using 0 bytes.
(%i2) a : 10^(10^5) $
Evaluation took 0.0192 seconds (0.0200 elapsed) using 96.047 KB.
(%i3) b : a^10 $
Evaluation took 1.1198 seconds (1.1194 elapsed) using 1023.875 KB.
(%i4) b : a^20 $
Evaluation took 4.5570 seconds (4.5607 elapsed) using 2.147 MB.
(%i5) 
```

Contrast with maxima-ecl:
```
$ rmaxima -l ecl
;;; Loading #P"/usr/lib64/ecl-21.2.1/sb-bsd-sockets.fas"
;;; Loading #P"/usr/lib64/ecl-21.2.1/sockets.fas"
Maxima 5.45.1 https://maxima.sourceforge.io
using Lisp ECL 21.2.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) showtime : true $
Evaluation took 0.0000 seconds (0.0000 elapsed)
(%i2) a : 10^(10^5) $
Evaluation took 0.0030 seconds (0.0020 elapsed)
(%i3) b : a^10 $
Evaluation took 0.0420 seconds (0.0440 elapsed)
(%i4) b : a^20 $
Evaluation took 0.0680 seconds (0.0450 elapsed)
(%i5) b : a^40 $
Evaluation took 0.0750 seconds (0.0780 elapsed)
(%i6) b : a^80 $
Evaluation took 0.2420 seconds (0.2000 elapsed)
(%i7) b : a^160 $
Evaluation took 0.4430 seconds (0.3890 elapsed)
(%i8) b : a^320 $
Evaluation took 0.8530 seconds (0.7970 elapsed)
(%i9) b : a^640 $
Evaluation took 1.7850 seconds (1.7040 elapsed)
(%i10) ) b : a^1280 $
Evaluation took 3.7550 seconds (3.6670 elapsed)
(%i11) 
```

Note: ecl compiles with gmp so that's probably where the long arithmetic comes from.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-11 15:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-04 19:19 [ISSUE] maxima (sbcl) arithmetic is very slow tornaria
2022-01-04 19:47 ` tornaria
2022-01-04 19:55 ` tornaria
2022-01-04 21:16 ` tornaria
2022-01-11 15:55 ` [ISSUE] [CLOSED] " leahneukirchen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).