Increase pretty printing line density#1733
Conversation
| switch (S->buffer->data[S->buffer->count - 1]) { | ||
| case ')': | ||
| case '}': | ||
| case ']': |
There was a problem hiding this comment.
Originally posted by @sogaiu in #1732 (comment):
(printf "%m" '{:a 1 :b 2 :c [:x :y]}) {:a 1 :b 2 :c [:x :y]}For this case, I like #1721's behavior better. How about you?
If it's specifically about mappings, I agree, and the backtracked line joins can be skipped for }. The current behavior is rather outrageous for something like (range 10), or printfing macro expansions.
My concern with this PR is rather on performance, since backtracking would multiply the cost by the container's depth. Though, it's rather cache-friendly so I'm probably just overthinking.
There was a problem hiding this comment.
I confess that I don't understand the details here (about backtracking) 😅
If it's simpler and more performant to leave things as-is, I would vote for that.
Regarding the original issue, I have some ideas of how to adjust things for my particular situation.
|
This seems off to me, mostly I think because I don't think any sort of backtracking should be needed. We can "measure" the size of a data structure before printing it.
That is, until someone tries to print (range 10000000) or some other large data structure. I recently added some limitations to sorting keys to avoid accidental quadratic behavior when printing large tables. |
|
I understand pretty printing as avoiding hardwrapping, thus the measurement must be of the printed data structure. This PR effectively does that for each data structure right before a newline. The current behavior insert newlines between all children, so quadratic performance would occurs in the worst case scenario of nested-tuples as a reversed linked list, e.g. ((((((() 1) 2) 3) 4) 5) 6). This PR should stop looking back after traversing the line length though, I implement that if this behavior is still wanted. |
|
Running some quick tests locally, even with forms that are not that complicated, this is a massive slow down: Current master: This branch: |
|
Thanks for the heads up, now the performance should be on par with master! There's also a width specifier for the multiline pretty format. |
|
FWIW, here are some local results: |
|
@McSinyx Did you find some issue? |
|
Yes, the width counting is off by a small margin 🤔 |
|
Should be fixed now! |
|
Here are some more measurements: |
|
LGTM, thanks to the work here! I think this would also be a good place to add more fuzzer stubs in the tools directory. |
|
Thanks for merging and following up with the fuzzer stubs! |
Resolve #1732, maybe?