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. The benefits are compelling (times given for a single invocation of a particular lazily-recursive multimethod): Baseline, no memoization: 17165ms After memoizing supers: 2874ms After memoizing supers & bases: 2749ms That's a big factor difference, and in aggregate, the impact would be quite huge. Memoizing bases is strictly redundant w.r.t. optimizing the use of isa?, as isa? only calls supers. However, assuming the safety of this approach, there's no harm in memoizing bases as well for those fns that do use it (like parents). I'd presume that a memoization that uses a WeakHashMap in the background would be far preferable to the built-in memoize fn in core now -- this would allow unloaded Classes to be dropped from the cache appropriately. Further, Class doesn't override hashCode or equals itself, so memoizing these fns should allow for multiple instances of the same Class (e.g. from different classloaders) to peacefully coexist. Given that, it seems to me that this approach is safe, at least with what I know about module systems, and the other factors associated with classloading, etc. There's the wildcard of what's going on in the JDK 7 future, but I can't usefully talk about that. Thoughts? If this is deemed safe and acceptable, I'd be very happy to produce a ticket + patch. - Chas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---