2019-07-03 13:36:50 |
Paul F. Dietz |
description |
The internal function SB-KERNEL:ASSERT-ERROR is called when an assertion fails. One of its arguments is a list of (<form> <value>) lists. This list is assembled at the caller.
Instead, change SB-KERNEL:ASSERT-ERROR to take two arguments in place of that one: the list of forms, and the list of their values. The list as previously passed can then be reconstructed in SB-KERNEL:ASSERT-ERROR itself. The list of forms is a compile time constant, so this reduces the amount of allocation at the caller by a factor of 3. More importantly, it reduces the size of the code footprint in user code for ASSERT. |
The internal function SB-KERNEL:ASSERT-ERROR is called when an assertion fails. One of its arguments is a list of (<form> <value>) lists. This list is assembled at the caller.
Instead, change SB-KERNEL:ASSERT-ERROR to take two arguments in place of that one: the list of forms, and the list of their values. The list as previously passed can then be reconstructed in SB-KERNEL:ASSERT-ERROR itself. The list of forms is a compile time constant, so this reduces the amount of allocation at the caller by a factor of 3. More importantly, it reduces the size of the code footprint in user code for ASSERT.
To get some idea of the savings, look at this code, which measures the caller overhead for invoking something that looks like SB-KERNEL:ASSERT-ERROR.
(defun ig (&rest args) (declare (ignore args)) nil)
(declaim (notinline ig))
(defun f1 (x y)
(ig '(eql x y) (list (list 'x x) (list 'y y)) nil "?"))
(defun f2 (x y)
(ig '(eql x y) '(x y) (list x y) nil "?"))
(defun g1 (x)
(ig '(zerop x) (list (list 'x x)) nil "?"))
(defun g2 (x)
(ig '(zerop x) '(x) (list x) nil "?"))
When compiled and disassembled, g1 -> g2 shrinks from 188 to 113 bytes, and
f1 -> f2 shrinks from 282 to 128 bytes (x86-64, Linux). |
|
2019-07-03 13:38:28 |
Paul F. Dietz |
description |
The internal function SB-KERNEL:ASSERT-ERROR is called when an assertion fails. One of its arguments is a list of (<form> <value>) lists. This list is assembled at the caller.
Instead, change SB-KERNEL:ASSERT-ERROR to take two arguments in place of that one: the list of forms, and the list of their values. The list as previously passed can then be reconstructed in SB-KERNEL:ASSERT-ERROR itself. The list of forms is a compile time constant, so this reduces the amount of allocation at the caller by a factor of 3. More importantly, it reduces the size of the code footprint in user code for ASSERT.
To get some idea of the savings, look at this code, which measures the caller overhead for invoking something that looks like SB-KERNEL:ASSERT-ERROR.
(defun ig (&rest args) (declare (ignore args)) nil)
(declaim (notinline ig))
(defun f1 (x y)
(ig '(eql x y) (list (list 'x x) (list 'y y)) nil "?"))
(defun f2 (x y)
(ig '(eql x y) '(x y) (list x y) nil "?"))
(defun g1 (x)
(ig '(zerop x) (list (list 'x x)) nil "?"))
(defun g2 (x)
(ig '(zerop x) '(x) (list x) nil "?"))
When compiled and disassembled, g1 -> g2 shrinks from 188 to 113 bytes, and
f1 -> f2 shrinks from 282 to 128 bytes (x86-64, Linux). |
The internal function SB-KERNEL:ASSERT-ERROR is called when an assertion fails. One of its arguments is a list of (<form> <value>) lists. This list is assembled at the caller.
Instead, change SB-KERNEL:ASSERT-ERROR to take two arguments in place of that one: the list of forms, and the list of their values. The list as previously passed can then be reconstructed in SB-KERNEL:ASSERT-ERROR itself. The list of forms is a compile time constant, so this reduces the amount of allocation at the caller by a factor of 3. More importantly, it reduces the size of the code footprint in user code for ASSERT.
To get some idea of the savings, look at this code, which measures the caller overhead for invoking something that looks like SB-KERNEL:ASSERT-ERROR.
(defun ig (&rest args) (declare (ignore args)) nil)
(declaim (notinline ig))
(defun f1 (x y)
(ig '(eql x y) (list (list 'x x) (list 'y y)) nil "?"))
(defun f2 (x y)
(ig '(eql x y) '(x y) (list x y) nil "?"))
(defun g1 (x)
(ig '(zerop x) (list (list 'x x)) nil "?"))
(defun g2 (x)
(ig '(zerop x) '(x) (list x) nil "?"))
When compiled and disassembled, g1 -> g2 shrinks from 188 to 113 bytes, and
f1 -> f2 shrinks from 282 to 128 bytes (x86-64, Linux).
Further optimization could be obtained by specializing SB-KERNEL:ASSERT-ERROR for cases of fixed numbers of forms and values. |
|