Replies: 4 comments 14 replies
-
Yeah, you're probably right.
Indeed. Bencode has no representation for |
Beta Was this translation helpful? Give feedback.
-
Optimizing things SGTM - thanks! The |
Beta Was this translation helpful? Give feedback.
-
I'm cautious both about introducing more API functions needlessly and about making breaking changes to such a internal part of the codebase.. probably the safe thing to do now is raise a deprecation warning on a 3-argument call, and then remove it in the future (Cider 2.0?) In the meantime I'll remove the argument entirely on my local fork and make sure nothing goes wrong (so far all seems fine) |
Beta Was this translation helpful? Give feedback.
-
Oops, I was wrong about the complexity analysis - A quick benchmark shows an average speedup factor of ~0.7 (30% decrease) for dicts with 10 keys, and ~0.4 (60% decrease) for dicts with 100 keys. In the worst-case comparison (key is at the start of dict, N=100), we get a 92% improvement, but I guess most response dicts are relatively small in practice. |
Beta Was this translation helpful? Give feedback.
-
nrepl-dict-get
is probably the #1 called function in all of Cider, so I was surprised to find that its implementation has an inefficient call tonrepl-dict-contains
,that turns from what should be a O(n) lookup into O(n²).(edit: see correction below)cider/nrepl-dict.el
Line 69 in 05e7570
Note that this check has no effect when the optional
default
argument is nil, and really only serves to distinguish the case where the key's value isnil
:One simple improvement would be to only perform the contains? check when
default
arg is non-nil, turning it back into O(n) in the 2-argument case.... In fact as far as I can tell, the 3-argument call to
nrepl-dict-get
is not used at all in the entire Cider and clj-refactor codebases! I guess it was originally written to mirror the semantics ofclojure.core/get
, overlooking the fact that plist lookups don't have the same O(1) performance guarantees as in Clojure.So another possible change might be to remove the optional argument entirely, or place a deprecation warning for future removal around its use. I believe nREPL responses can't even contain nils in the first place(?), so its usage would basically be equivalent to the regular Elisp idiom of
(or (nrepl-dict-get ..) <default>)
.Beta Was this translation helpful? Give feedback.
All reactions