Skip to content
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

[Fix #1859] In message log insert large objects on request only #1861

Merged
merged 5 commits into from
Oct 10, 2016

Conversation

vspinu
Copy link
Contributor

@vspinu vspinu commented Oct 10, 2016

Instead of removing the pp logic I have moved it to a different place. The pp print of big dicts, lists and strings now happens on requests only, i.e. when the user clicks the expansion button. This completely removes logger overhead. In my tests I don't see nrepl-message-log in the profiler tree anymore.

Not closing the #1758 as there seem to be much more going on there.

(nrepl--insert-button "(dict ...)" object)
(nrepl--pp-listlike object foreground button)))
(t
(if (and button (> (length object) 10))
Copy link
Member

Choose a reason for hiding this comment

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

Probably constants like this one should be moved to defcustoms (as some people might want to tune them).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks rather useless option to me. Even though it's arbitrary I don't see why would anyone care to change that.

If we add config here, we should probably add a config for the minimal size of the dict that is buttonized. Currently I am buttonizing all non-empty dicts. One option would be to have same constant for both dicts and lists, but that would mean printing potentially deeply nested objects if at each level there is a small list.

Also strings are truncated if they are longer than 80chars. Do you want an option for that as well? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, there is a now a defunct nrepl-dict-max-message-size which I forgot to remove. IMO, unfolding dicts is an unnecessary overhead. People can always click when needed and it saves quite some space.

One slight drawback of this design that you cannot copy-paste or save the log directly because there is no text in those buttons in the first place. We can have a small utility nrepl-log-unfold-all-buttons to handle this.

Copy link
Member

Choose a reason for hiding this comment

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

If we add config here, we should probably add a config for the minimal size of the dict that is buttonized. Currently I am buttonizing all non-empty dicts. One option would be to have same constant for both dicts and lists, but that would mean printing potentially deeply nested objects if at each level there is a small list.

Oh, I've missed this. I guess top-level dicts shouldn't be folded, though, as you'll get all your context about a request/response.

I generally don't like magic numbers flowing around. I'm fine with not using defcustoms, but even consts make it easier to read the code. You can spruce up some comments here and there in the folding logic, as some decision might not be obvious to everyone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess top-level dicts shouldn't be folded,

The top dicts are not folded, only 1st level dicts are (aka those which display with (dict ...). It looks like this:

(--> 
  op  "describe"
  session  "67aafc4f-8ba7-4b41-9a20-8f418ca0da8c"
  id  "8"
)
(<-- 
  aux  (dict ...)
  id  "8"
  ops  (dict ...)
  session  "67aafc4f-8ba7-4b41-9a20-8f418ca0da8c"
  status  ("done")
  versions  (dict ...)
)

You can spruce up some comments here and there in the folding logic, as some decision might not be obvious to everyone.

Ok. I will get all these into a local let. You can extract them into variables if it will ever be a need for it.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me.

(setq object (substring-no-properties object)))
(pp object (current-buffer))
(unless (listp object) (insert "\n")))
(defun nrepl--insert-button (label object)
Copy link
Member

Choose a reason for hiding this comment

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

Guess a better name would be nrepl--log-insert-button or something like this.

Copy link
Member

Choose a reason for hiding this comment

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

One slight drawback of this design that you cannot copy-paste or save the log directly because there is no text in those buttons in the first place. We can have a small utility nrepl-log-unfold-all-buttons to handle this.

Sounds reasonable to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Guess a better name would be nrepl--log-insert-button or something like this.

Then all others should be renamed for consistency: nrepl--expand-button, nrepl--message-color, nrepl--expand-button-mouse, nrepl--pp. There is no consistency with respect to nrepl-log-.. and nrepl-message-.. prefix either.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, ideally we should renamed all the related stuff in some consistent manner, but that's not super important. If you'd like to tackle it - that'd be great, otherwise I can do it down the road.

@vspinu
Copy link
Contributor Author

vspinu commented Oct 10, 2016

Ok. I have parameterized the constants and renamed the main logging functions with nrepl-log- prefix.

I also fixed the keymap problems on buttons on this ocassion. Fix in #1568, 814692d used local-map property, which completely overwrites the major-mode map. So things like TAB, n,p and now e/E wouldn't work on buttons.

@bbatsov bbatsov merged commit de7d734 into clojure-emacs:master Oct 10, 2016
@bbatsov
Copy link
Member

bbatsov commented Oct 10, 2016

Thanks!

@vspinu vspinu deleted the pp-speed branch June 20, 2018 10:38
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