camsaul / methodical

Functional and flexible multimethods for Clojure. Nondestructive multimethod construction, CLOS-style aux methods and method combinations, partial-default dispatch, easy next-method invocation, helpful debugging tools, and more.
Eclipse Public License 2.0
295 stars 19 forks source link

[dispatcher] Optimize primary method calculation #152

Closed alexander-yakushev closed 2 months ago

alexander-yakushev commented 2 months ago

This PR makes small optimizations to the process of computing a primary method (namely, to matching-primary-methods function). The changes are mostly structural – replacing lazy transforms and expensive iteration with eager and optimized counterparts.

At first, I was under the impression that the time to construct a method for a dispatch value should not matter because of caching, but here and there in Metabase I find cases where the method is reconstructed – either because the method can't be cached, or in situations like https://github.com/camsaul/toucan2/pull/180. Hence, improving the efficiency of this otherwise cacheable process is still worth doing.