Compiler optimization of INTERN similar to what's in CCL
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Undecided
|
Douglas Katzman |
Bug Description
CCL has a compiler macro for INTERN that optimizes the common case of a constant package designator.
In CCL, this works as follows:
(1) Maintain a 1-1 mapping from simple strings (package names or nicknames) to package-ref objects.
(2) Each package-ref is a structure containing the unique (up to EQUAL) string that maps to it, and the package it refers to.
(3) The compiler macro expands to a LOAD-TIME-VALUE expression that builds this structure.
(4) There is also a MAKE-LOAD-FORM for the structure.
(5) When a package is defined or redefined, any mappings for relevant names are updated so the package field is still valid (it may be NIL if the package gets deleted.)
This makes these common calls to intern fast, and has a noticeable effect on the speed of applications, in particular ACL2.
Unfortunately, package local nicknames complicate this picture, since the package is no longer just a function of the package name, but also of the value of *PACKAGE*. PLNs are being added to CCL (thanks phoe!), so changes to recover the speed improvement were suggested (by me) at their github. The easiest might be this:
(6) Add a boolean field to the package-ref structure that is true iff this string is involved in PLNs somehow (that is, it is used as a PLN in some package that has been loaded into the system). If this field is true, default back to the current explicit lookup (that is, disable the optimization).
With this change, the common case of no PLNs becomes fast again.
Also: it may be desirable to have PLNs be prohibited for names or nicknames of standard packages.
Changed in sbcl: | |
status: | New → Fix Committed |
assignee: | nobody → Douglas Katzman (dougk) |
Changed in sbcl: | |
status: | Fix Committed → Fix Released |
Do you have a benchmark that presents some compelling evidence that we're slow because of the implicit FIND-PACKAGE (as part of intern) per se?
a most-recently-used cache on name -> package that is also sensitive to *package* would be lot simpler, and localized to find-package.