On Aug 28, 2009, at 10:57 PM, Chas Emerick wrote:
>
> In the course of doing some profiling tonight, I hit on a hotspot in
> some particularly multimethod- and isa?-heavy code. It didn't take me
> long to find that the bases and supers support fns for isa? were at
> the root of the issue, with bases in particular taking more time in
> aggregate than the bodies of the multimethods themselves.
>
> A quick fix for this was to memoize bases and supers. Given that
> these fns are concerned only with Classes (and not the dynamic
> hierarchies, etc), this would seem to be safe in general.
As a quick followup to this, here's a simple macro that folks can use
to apply this optimization with a minimum of fuss in a given context:
(defmacro with-fast-multimethods
[& body]
`(binding [clojure.core/supers (memoize clojure.core/supers)
clojure.core/bases (memoize clojure.core/bases)]
~...@body))
- Chas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---