Skip to content

Conversation

@frenchy64
Copy link
Contributor

While trying to implement s/defprotocol, I needed the following invariant to hold in Clojure to access __methodImplCache:

(let [f (s/fn this [] this)]
  (identical? f (f)))

The fix I chose was to use ^{:schema schema} (fn ...) instead of (with-meta (fn ...) {:schema schema}). I believe this also fixed all the documented performance caveats for s/fn in Clojure as it means wrappers are eliminated.

The perf characteristics for CLJS seem unchanged (still uses the wrapper). I worked around CLJS-968 by placing the function evaluation in non-tail position. I decided working around this issue was better than using macros/if-cljs (which I treat as a last resort).

I also moved a test, please ignore whitespace changes when reviewing.

Copy link
Member

@w01fe w01fe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks!

@frenchy64
Copy link
Contributor Author

There was an oversight in lein all that meant the latest cljs was never tested. I needed to drop Clojure 1.7 from the test suite because CLJS doesn't work with it (but we only support Clojure 1.8 and later anyway).

@frenchy64 frenchy64 merged commit ac25cad into plumatic:master Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants