Reduce code size of call to SB-KERNEL:ASSERT-ERROR

Bug #1835221 reported by Paul F. Dietz on 2019-07-03
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Undecided
Unassigned

Bug 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).

Further optimization could be obtained by specializing SB-KERNEL:ASSERT-ERROR for cases of fixed numbers of forms and values.

description: updated
description: updated
Stas Boukarev (stassats) on 2019-07-03
Changed in sbcl:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers