Steel Bank Common Lisp

unneccessary value cells for NLXs

Reported by Nikodemus Siivola on 2012-05-21
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Medium
Unassigned

Bug Description

  (defun feh (x)
    (flet ((meh () (return-from feh 'meh)))
     (typecase x
      (cons (or (car x) (meh)))
      (t (meh)))))

The compiler should be able to figure out that MEH cannot escape, but...

  CL-USER> (time (loop repeat 10000 do (feh t)))
  Evaluation took:
    0.001 seconds of real time
    0.001026 seconds of total run time (0.000810 user, 0.000216 system)
    100.00% CPU
    1,953,003 processor cycles
    163,840 bytes consed

...all from value cell allocation for checking the return. The cost is non-trivial. With CHECK-TAG-EXISTENCE 0:

  CL-USER> (time (loop repeat 10000 do (feh t)))
  Evaluation took:
    0.000 seconds of real time
    0.000355 seconds of total run time (0.000351 user, 0.000004 system)
    100.00% CPU
    916,500 processor cycles
    0 bytes consed

Meh.

Changed in sbcl:
assignee: nobody → Nikodemus Siivola (nikodemus)
Nikodemus Siivola (nikodemus) wrote :

Something like this.

Nikodemus Siivola (nikodemus) wrote :

commit 3352e447d32d6786a5609cd53c6b3f2be7ab3e08
Author: Nikodemus Siivola <email address hidden>
Date: Mon May 21 23:30:54 2012 +0300

    elide value cells for NLXs when it seems like the right thing

      Previously we only did this for unsafe code.

      Now we also elide them for

       (1) exits from DX functions: if a DX function escapes its proper context,
           trying to perform NLX to a stale tag is the least of our worries.

       (2) functions that cannot escape. Since the escape analysis isn't yet very
           tested, disable it for safe code, though. If this raises hairs on your
           neck, consider this: even if our analysis is wrong, and a function we
           didn't think could escape does, we're in the land of "undefined
           consequences" anyways.

           If you're wondering if this is worth it, compare

             (defun feh (x)
               (flet ((meh () (return-from feh 'meh)))
                 (typecase x
                  (cons (or (car x) (meh)))
                  (t (meh)))))

             (time (loop repeat 10000 do (feh t)))

           with and without the escape analysis.

Changed in sbcl:
assignee: Nikodemus Siivola (nikodemus) → nobody
status: Triaged → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers