Giter Club home page Giter Club logo

Comments (2)

scymtym avatar scymtym commented on July 18, 2024

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.

alex-gutev avatar alex-gutev commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.