3 ms·
If I knew the types beforehand at compile time then I don't really _need_ the generic functions per say. Is there a CLOS implementation with inline caches for
by admax88q 6y ago
If I knew the types beforehand at compile time then I don't really _need_ the generic functions per say.
Is there a CLOS implementation with inline caches for generic method dispatch?
- reikonomusha 6y agoDo you mean something like this? https://github.com/guicho271828/inlined-generic-function https://github.com/guicho271828/inlined-generic-function Even if you know all the types, you still have polymorphism that can’t be efficiently monomorphized without an exponential space penalty.
- admax88q 6y agoI don't think that's what I was looking for. That talks about dispatching generic functions at compile time. > you still have polymorphism that can’t be efficiently monomorphized without an exponential space penalty. Wouldn't it be linear at each call site only by the number of types that actually reach that call site? Plus you don't have to cache _all_ types at the call site, only the most frequent ones. In Java and JS for instance, dynamic dispatch is JITed away at hot spots, and can be un-jitted later to reclaim space if the spot is no longer hot. I generally don't care if a dynamic dispatch is slow if I'm only calling it a few times, but in a tight loop I want it to be inlined as much as possible.
- fiddlerwoaroof 6y agoAlmost all of them have something like that: Robert Strandh has a technique that looks promising[1] and is being implemented as a library, I believe. CLOS’s customization hooks allow you to switch out the implementation of “generic function” on a case-by-case basis which can be used to implement this sort of optimization. [1]: http://metamodular.com/SICL/generic-dispatch.pdf http://metamodular.com/SICL/generic-dispatch.pdf