Re: Add jsonb_compact(...) for whitespace-free jsonb to text

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Ryan Pedela <rpedela(at)datalanche(dot)com>, Sehrope Sarkuni <sehrope(at)jackdb(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add jsonb_compact(...) for whitespace-free jsonb to text
Date: 2016-04-27 21:05:18
Message-ID: 20160427210518.GM10850@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

* Merlin Moncure (mmoncure(at)gmail(dot)com) wrote:
> On Tue, Apr 26, 2016 at 11:49 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > As I mentioned to Sehrope on IRC, at least for my 2c, if you want a
> > compact JSON format to reduce the amount of traffic over the wire or to
> > do things with on the client side, we should probably come up with a
> > binary format, rather than just hack out the whitespace. It's not like
> > representing numbers using ASCII characters is terribly efficient
> > either.
>
> -1
>
> This will benefit pretty much nobody unless you are writing a hand
> crafted C application that consumes and processes the data directly.

That's not accurate. All that's needed is for the libraries which
either wrap libpq or re-implement it to be updated to understand the
format and then convert the data into whatever structure makes sense for
the language (or library that the language includes for working with
JSON data).

One of the unfortunate realities with JSON is that there isn't a
terribly good binary representation, afaik. As I understand it, BSON
doesn't support all the JSON structures that we do; if it did, I'd
suggest we provide a way to convert our structure into BSON.

> I'd venture to guess this is a tiny fraction of pg users these days.
> I do not understand at all the objection to removing whitespace.
> Extra whitespace does nothing but pad the document as humans will
> always run the document through a prettifier tuned to their specific
> requirements (generally starting with, intelligent placement of
> newlines) if reading directly.

The objection is that it's a terribly poor solution as it simply makes
things ugly for a pretty small amount of improvement. Looking at it
from the perspective of just "whitespace is bad!" it might look like a
good answer to just remove whitespace, but we should be looking at it
from the perspective of "how do we make this more efficient?". Under
that lense, removing whitespace appears to be minimally effective
whereas passing the data back in a binary structure looks likely to
greatly improve the efficiency on a number of levels.

> Also, binary formats are not always smaller than text formats.

While true, I don't think that would be true in this case.

Of course, there's nothing like actually trying it and seeing.

Thanks!

Stephen

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2016-04-27 21:06:00 Re: Parallel indicators not written by pg_get_functiondef
Previous Message Bruce Momjian 2016-04-27 21:01:14 Re: pgindent