-
-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of nrepl-dict-get #3713
Conversation
(if (nrepl-dict-contains dict key) | ||
(lax-plist-get (cdr dict) key) | ||
default) | ||
(or (lax-plist-get (cdr dict) key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably add some comments here, so someone won't "optimize" away the optimizations in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, and rebased to resolve the conflicts
Btw, how about removing such checks:
They obviously have some overhead and seem pointless in practice as we do expect a dict to be pass. I've never been found of so defensive style of programming. (although I do get you're getting nicer errors when you mess up something this way) |
Ah, I see you've inlined |
Avoid full traversal of dict in 2-argument call
Calling the function with 3 arguments will continue to work, but raise a warning during byte compilation.
Yeah, I didn't specifically profile the effect of One other thought I had was whether we could overload all of these functions to accept a hash-table as argument, that should be a non-breaking change and allow us to swap out the implementations of those huge dicts under the hood, similar to how Clojure treats PersistentArrayMap / PersistentHashMap? Something like (defun nrepl-dict-get (dict key)
(cond ((null dict) nil)
((nrepl-dict-p dict)
<<current-implementation>>)
((hash-table-p dict)
(gethash key dict))
(t
(error "Not an nREPL dict object: %s" dict)))) |
7554abe
to
344005f
Compare
I think that's a pretty reasonable idea, as I was thinking something quite similar over the weekend when we started to discuss this. It'd be an easy and fairly transparent change. |
Sounds really interesting. It will be nice to see some examples of where we can actually use hash tables instead of dicts. |
Yeah, I've checked the discussion. I guess it is just hard to wrap my head around how exactly this should work. Will be looking for further updates on the topic! |
See #3711
These changes do not affect the semantics of nrepl-dict-get (covered by existing tests), but byte compilation will raise a warning on any 3-argument usage, hopefully decreasing the risk of its future removal.
Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):
eldev test
)eldev lint
) which is based onelisp-lint
and includescheckdoc
, check-declare, packaging metadata, indentation, and trailing whitespace checks.Thanks!
If you're just starting out to hack on CIDER you might find this section of its
manual extremely useful.