Comments (2)
I think the slowness in the first case can be explained by noting the time at which the effects of the defgeneric
expansion happen: the ref
call in test
can be optimized only during compilation of test
so only compile-time effects of the defgeneric
expansion have already happened when test
is compiled (in the first case -- in the other cases, all effects of the defgeneric
expansion have already happened when test
is compiled).
The defgeneric
expansion contains eval-when
forms to address the issue, but those only work at the top-level. let
and when
make their sub-forms non-top-level. This effect can be seen by changing make-static-dispatch
to emit
(eval-when (:compile-toplevel :load-toplevel :execute)
(print "should be at compile-time")
(unless (sb-c::info :function :info ',name)
(sb-c:defknown ,name * * nil :overwrite-fndb-silently t)))
Compiling and loading @mfiano 's example via (load (compile-file "/tmp/dispatch.lisp"))
then results in
; compiling file "/tmp/dispatch.lisp" (written 08 AUG 2021 05:43:37 PM):
…
; processing (DEFSTRUCT (AGGREGATE # ...) ...)
; processing (DEFGENERIC REF ...)
; processing (DEFUN TEST ...)
; wrote /tmp/dispatch.fasl
; compilation finished in 0:00:00.036
"should be at compile-time"
T
That is, the effect happens at load-time, not compile-time.
from static-dispatch.
To avoid these difference you should define the generic functions and their methods in a separate file from the code which uses them. As already mentioned by @scymtym, what's happening here is that since they are contained in the same file, the deftransform
forms emitted by static-dispatch, which are responsible for the actual inlining, only take effect after the entire file is compiled, that is after the test
function, which calls the generic function, is compiled. As a result no inlining takes place in test
. On other implementations, where compiler-macros are used, you will get a warning however on SBCL, where deftransform
is used there is no warning since the transform isn't even registered yet, and hence is never called.
I don't know what's causing the difference between the second and third case. There shouldn't be any difference unless SBCL is performing more optimizations when the test
function is recompiled. I will look into that further.
from static-dispatch.
Related Issues (14)
- Error during compiler-macroexpansion of HOT 9
- ignore/ignorable declarations in methods emit style-warnings HOT 1
- find-method% conditionalization for LispWorks HOT 1
- Compile-time (ASDF:COMPILE-OP) error HOT 2
- Some systems failed to build for Quicklisp dist HOT 3
- Reserved name AUX[.lisp] blocks loading on windows
- cl-arrows is proprietary software HOT 1
- ASDF Style warning HOT 5
- Providing compiler notes HOT 8
- Basic usage fails to compile on SBCL 2.1.7 HOT 3
- static-dispatch-warn with ALL fails to parse HOT 2
- Confusion over static-dispatch-type HOT 2
- method-descriptions are not honored HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from static-dispatch.