svref | 7 Nov 04:52 2004
Picon

(setf uffi:get-slot-value) slowness in sbcl

I've got compiled code that looks like:

(uffi:with-foreign-object (rect 'sdl:rect)
  (setf (uffi:get-slot-value rect 'sdl:rect 'sdl::x) 137)
  ;; do something with rect...
  )

Every time I execute this pre-compiled code, I get a warning about

; compilation unit finished
;   printed 1 note
; in: LAMBDA NIL
;     (SB-ALIEN-INTERNALS:NATURALIZE
;    (SB-SYS:SAP+ SB-ALIEN::SAP (/ SB-ALIEN::OFFSET SB-VM:N-BYTE-BITS))
;    '#<SB-ALIEN-INTERNALS:ALIEN-RECORD-TYPE (STRUCT SDL:RECT
;                                                    (SDL::X #)
;                                                    (SDL::Y #)
;                                                    (SDL::W #)
;                                                    (SDL::H #))>)
; ==>
;   (SB-ALIEN-INTERNALS:%SAP-ALIEN ALIEN
;         '#<SB-ALIEN-INTERNALS:ALIEN-RECORD-TYPE
;              (STRUCT SDL:RECT (SDL::X #) (SDL::Y #) (SDL::W #) (SDL::H #))>)
; 
; note: unable to
;   optimize
; because:
;   could not optimize away %SAP-ALIEN: forced to do runtime 
; allocation of alien-value structure

(Continue reading)

David Morse | 7 Nov 06:38 2004
Picon

Re: (setf uffi:get-slot-value) slowness in sbcl

My apologies, I was confused in my previous post.

In the following function the "declare" on line two cuts execution time 
by a factor of 1000.  Without it, it prints out a warnings similar to 
the ones in the last post per call to sdl:surface-w or sdl:surface-h 
(which are prolly just uffi:get-slot-value calls after inline expansion).

Is there some way to rewrite that declaration to use the uffi package 
instead of the nonportable sb-alien package?

(defun draw-bmp (surface screen x y)
   (declare (type (sb-alien:alien (* sdl:surface)) screen surface))
   (let ((w (sdl:surface-w surface))
	(h (sdl:surface-h surface)))
     (uffi:with-foreign-object (rect 'sdl:rect)
       (setf (sdl:rect-x rect) x
	    (sdl:rect-y rect) y
	    (sdl:rect-w rect) w
	    (sdl:rect-h rect) h)
       (sdl:blit-surface surface the-null-sdl-rect screen rect)
       (sdl:update-rect screen x y w h)
       nil)))

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
Alexey Dejneka | 7 Nov 10:31 2004
X-Face
Picon

Re: (setf uffi:get-slot-value) slowness in sbcl

Hello,

David Morse <svref <at> yahoo.com> writes:

> Is there some way to rewrite that declaration to use the uffi package
> instead of the nonportable sb-alien package?
>
> (defun draw-bmp (surface screen x y)
>    (declare (type (sb-alien:alien (* sdl:surface)) screen surface))

(uffi:def-type surface-ptr '(* sdl:surface))
...
  (declare (type surface-ptr screen surface))

--

-- 
Regards,
Alexey Dejneka

"Alas, the spheres of truth are less transparent than those of
illusion." -- L.E.J. Brouwer

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
David Morse | 8 Nov 03:46 2004
Picon

Re: *print-alien-types-to-death* ?


SBCL prints out alien types with gusto.  Is there some special variable
I can set somewhere to get it to chill out a little?  For example, I'd
prefer the ambiguous terseness of this:

#<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X08284F10 :TYPE (*
(SB-ALIEN:STRUCT SDL:SURFACE ...))>

to the information overload of what I currently get:

> #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X08284F10 :TYPE (*
> 
>                                                            (SB-ALIEN:STRUCT
> 
>                                                             SDL:SURFACE
> 
>                                                             (SDL::FLAGS
> 
>                                                              (SB-ALIEN:UNSIGNED
> 
>                                                               32))
> 
>                                                             (FORMAT
> 
>                                                              (*
> 
>                                                               (SB-ALIEN:STRUCT
> 

... nausiating amounts of pretty printing deleted ...]
(Continue reading)

Alexey Dejneka | 8 Nov 06:42 2004
X-Face
Picon

Re: Re: *print-alien-types-to-death* ?

Hello,

David Morse <svref <at> yahoo.com> writes:

> SBCL prints out alien types with gusto.  Is there some special variable
> I can set somewhere to get it to chill out a little?  For example, I'd
> prefer the ambiguous terseness of this:
>
> #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X08284F10 :TYPE (*
> (SB-ALIEN:STRUCT SDL:SURFACE ...))>

AFAIK there are no variables, controlling specifically printing of
aliens, but you can overwrite our printing methods; or just add an
:AROUND method:

(defvar *alien-print-length* 2)
(defmethod print-object :around ((alien sb-alien-internals:alien-value)
                                 stream)
  (let ((*print-length* *alien-print-length*))
    (call-next-method)))

--

-- 
Regards,
Alexey Dejneka

"Alas, the spheres of truth are less transparent than those of
illusion." -- L.E.J. Brouwer

-------------------------------------------------------
This SF.Net email is sponsored by:
(Continue reading)

David Morse | 9 Nov 04:35 2004
Picon

warnings about alien memory allocation

I'm starting to think the compiler's a little TOO worried about
runtime allocation of alien-value structures.  Nobody wants a compiler
warning for every time a call to "list" forces a cons cell to be
allocated ... thus nobody wants this warning either:

* (defun foo () (sb-alien:make-alien (sb-alien:struct sdl:color)))
; in: LAMBDA NIL
;     (MAKE-ALIEN (STRUCT SDL:COLOR))
; ==>
;   (SB-ALIEN-INTERNALS:%SAP-ALIEN (SB-ALIEN::%MAKE-ALIEN (* 32 1))
;                                  '#<SB-ALIEN-INTERNALS:ALIEN-POINTER-TYPE (*
;                                                                            (STRUCT
;                                                                             SDL:COLOR
;                                                                             #
;                                                                             #
;                                                                             #
;                                                                             #))>)
; 
; note: unable to
;   optimize
; because:
;   could not optimize away %SAP-ALIEN: forced to do runtime 
; allocation of alien-value structure
; compilation unit finished
;   printed 1 note

FOO

-------------------------------------------------------
This SF.Net email is sponsored by:
(Continue reading)

Edi Weitz | 9 Nov 09:57 2004
Picon

Access to backtraces

I have the following code in TBNL[1] which is used to print backtraces
to the logfile and/or send them to the browser.

  #+:sbcl
  (defun get-backtrace (error)
    (declare (ignore error))
    (with-output-to-string (s)
      (let ((sb-debug:*debug-print-level* nil)
            (sb-debug:*debug-print-length* nil))
        (sb-debug:backtrace most-positive-fixnum s))))

Friedrich Dominicus told me that this won't work with newer SBCL
versions. How do I change it to make it work again and how do I
conditionalize it to do the right thing depending on the SBCL version?

Thanks,
Edi.

[1] <http://weitz.de/tbnl/>

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
Christophe Rhodes | 9 Nov 13:32 2004
Picon
Picon

Re: warnings about alien memory allocation

David Morse <dm <at> osaurus.us> writes:

> I'm starting to think the compiler's a little TOO worried about
> runtime allocation of alien-value structures.  Nobody wants a compiler
> warning for every time a call to "list" forces a cons cell to be
> allocated ... thus nobody wants this warning either:

Maybe.  On the other hand, I suspect that heap allocation of aliens is
orders of magnitude more expensive than heap allocation of lists --
particularly since in the general case stack allocation of aliens is
possible, which is not true for allocation of lists.

At least this way round, when people complain about several missing
orders of magnitude of alien performance, we can point to the compiler
notes that have resulted from their compilation. :-)

Cheers,

Christophe

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
Nikodemus Siivola | 9 Nov 14:18 2004
Picon
Picon

Re: Access to backtraces

On Tue, 9 Nov 2004, Edi Weitz wrote:

> I have the following code in TBNL[1] which is used to print backtraces
> to the logfile and/or send them to the browser.
>
>  #+:sbcl
>  (defun get-backtrace (error)
>    (declare (ignore error))
>    (with-output-to-string (s)
>      (let ((sb-debug:*debug-print-level* nil)
>            (sb-debug:*debug-print-length* nil))
>        (sb-debug:backtrace most-positive-fixnum s))))
>
> Friedrich Dominicus told me that this won't work with newer SBCL
> versions. How do I change it to make it work again and how do I
> conditionalize it to do the right thing depending on the SBCL version?

In newer SBCL versions sb-debug:*debug-print-foo* variables have been 
replaced with sb-ext:*debug-print-variable-alist* -- you can check for 
existence of that symbol with FIND-SYMBOL and act accordingly, eg:

  (let ((*debug-print-variable-alist*
         (list* '(*print-level* . nil) '(*print-length* . nil)
                *debug-print-variable-alist*)))
       ...)

However, you might be better served by sb-debug:backtrace-as-list and
something like

  (defun print-backtrace (stream &optional (from 'print-backtrace))
(Continue reading)

Edi Weitz | 9 Nov 15:15 2004
Picon

Re: Access to backtraces

On Tue, 9 Nov 2004 15:18:53 +0200 (EET), Nikodemus Siivola <tsiivola <at> cc.hut.fi> wrote:

> In newer SBCL versions sb-debug:*debug-print-foo* variables have
> been replaced with sb-ext:*debug-print-variable-alist* -- you can
> check for existence of that symbol with FIND-SYMBOL and act
> accordingly, eg:
>
>   (let ((*debug-print-variable-alist*
>          (list* '(*print-level* . nil) '(*print-length* . nil)
>                 *debug-print-variable-alist*)))
>        ...)

Thanks, I'll add something like this.

> However, you might be better served by sb-debug:backtrace-as-list
> and something like
>
>   (defun print-backtrace (stream &optional (from 'print-backtrace))
>     (let* ((stack (sb-debug:backtrace-as-list))
>            (top (or (position from stack :key #'car) -1))
>            (count -1))
>       (with-standard-io-syntax
>        (dolist (frame (nthcdr (1+ top) stack))
>           (format stream "~D: ~A~%" (incf count) frame)))))
>
> ...as this should work equally well in both older and newer SBCL's,
> and is a bit more customizable to boot.

Yeah, but it doesn't look as nice... :)

(Continue reading)


Gmane