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

Provide custom pprint functionality #193

Open
bbatsov opened this issue Oct 2, 2023 · 3 comments
Open

Provide custom pprint functionality #193

bbatsov opened this issue Oct 2, 2023 · 3 comments

Comments

@bbatsov
Copy link
Member

bbatsov commented Oct 2, 2023

The following thread on the Clojurians Slack caught my attention https://clojurians.slack.com/archives/C04CAKAGADU/p1695973819828719

So I've been using clojure.pprint/pprint for my pretty-printing needs so far, but it's really quite slow. I can't use Fipp because I don't want to take any dependencies (and because of e.g. https://github.com/brandonbloom/fipp/issues/37), so I thought I'd have a go at making my own pretty-printer.
What I have so far is dozens, sometimes hundreds of times faster than clojure.pprint/pprint, and 12x-15x faster than fipp.edn/pprint at Fipp's own benchmark. (It also allocates 10-25x fewer bytes than clojure.pprint/pprint or fipp.edn/pprint.) The implementation (https://github.com/eerohele/tab/blob/b5f1c0dd86349d05184d59746a017d9ed27e852d/src/tab/impl/pprint.clj) is ~200 lines of code. There are some benchmark results here: https://github.com/eerohele/tab/actions/runs/6348406766/job/17244962062#step:7:365
One tradeoff is that it's not customizable like clojure.pprint or Fipp, but that's not something I really need.
Anyway, I figured I'd throw this out there in case anyone needs something like this, or if anyone has any ideas for improving the current impl.

Perhaps it's worth inlining this in Orchard, given it's both quite simple and fast.

@vemv
Copy link
Member

vemv commented Oct 2, 2023

Seems neat!

One thing to consider is that Emacs itself is often the bottleneck when rendering large pprinted objects.

(which isn't a frequent problem as far as I've experienced, thanks to the trimming that is enforced past a certain byte count)

@bbatsov
Copy link
Member Author

bbatsov commented Oct 2, 2023

Emacs is the bottleneck when rendering a lot of text in general. :-) I think it does better with pprinted content than average, mostly because there are no very long lines, which have been a historical weakness of its text rendering engine.

@vemv
Copy link
Member

vemv commented Oct 2, 2023

One point in favor of a custom printer would be the ability to elide commas.

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

No branches or pull requests

2 participants