Re: [PATCH] cli: notmuch-show with framing newlines between threads in JSON.
authorTomi Ollila <tomi.ollila@iki.fi>
Mon, 2 Jul 2012 12:29:16 +0000 (15:29 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:56 +0000 (09:47 -0800)
29/5056ccca553a640ef56bf5930883f9dd285c7e [new file with mode: 0644]

diff --git a/29/5056ccca553a640ef56bf5930883f9dd285c7e b/29/5056ccca553a640ef56bf5930883f9dd285c7e
new file mode 100644 (file)
index 0000000..01cd934
--- /dev/null
@@ -0,0 +1,163 @@
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 7ED20431FBC\r
+       for <notmuch@notmuchmail.org>; Mon,  2 Jul 2012 05:29:07 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id V9GKb7yDEgwS for <notmuch@notmuchmail.org>;\r
+       Mon,  2 Jul 2012 05:29:06 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 0E684431FAF\r
+       for <notmuch@notmuchmail.org>; Mon,  2 Jul 2012 05:29:06 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+       id 1565C100637; Mon,  2 Jul 2012 15:29:16 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Austin Clements <amdragon@MIT.EDU>,\r
+       Mark Walters <markwalters1009@gmail.com>, Peter Feigl <craven@gmx.net>\r
+Subject: Re: [PATCH] cli: notmuch-show with framing newlines between threads\r
+       in JSON.\r
+In-Reply-To: <20120702035241.GD6220@mit.edu>\r
+References: <1341041024-5342-1-git-send-email-markwalters1009@gmail.com>\r
+       <m24npr8701.fsf@guru.guru-group.fi>\r
+       <20120702001215.GC6220@mit.edu> <20120702035241.GD6220@mit.edu>\r
+User-Agent: Notmuch/0.13.2+7~g2fb5bbc (http://notmuchmail.org) Emacs/23.1.1\r
+       (x86_64-redhat-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Mon, 02 Jul 2012 15:29:16 +0300\r
+Message-ID: <m2obnys5wj.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 02 Jul 2012 12:29:07 -0000\r
+\r
+On Mon, Jul 02 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
+\r
+> Quoth myself on Jul 01 at  8:12 pm:\r
+>> Quoth Tomi Ollila on Jul 02 at  1:13 am:\r
+>> > On Sat, Jun 30 2012, Mark Walters <markwalters1009@gmail.com> wrote:\r
+>> > \r
+>> > > Add newlines between complete threads to make asynchronous parsing\r
+>> > > of the JSON easier.\r
+>> > > ---\r
+>> > >\r
+>> > > notmuch-pick uses the JSON output of notmuch show but, in many cases,\r
+>> > > for many threads. This can take quite a long time when displaying a\r
+>> > > large number of messages (say 20 seconds for the 10,000 messages in\r
+>> > > the notmuch archive). Thus it is desirable to display results\r
+>> > > incrementally in the same way that search currently does.\r
+>> > >\r
+>> > > To make this easier this patch adds newlines between each toplevel\r
+>> > > thread. So the ouput becomes\r
+>> > >\r
+>> > > [\r
+>> > > thread1\r
+>> > > , thread2\r
+>> > > , thread3\r
+>> > > ...\r
+>> > > , last_thread\r
+>> > > ]\r
+>> > >\r
+>> > > Thus the parser can easily tell if it has enough data to do some more\r
+>> > > parsing.\r
+>> > >\r
+>> > > Obviously, this changes the JSON output. This should not break any\r
+>> > > consumer as the JSON parsers should not mind. However, it does break\r
+>> > > several tests. Obviously, I will fix these but I wanted to check if\r
+>> > > people were basically happy with the change first.\r
+>> > \r
+>> > To provide this feature rather than relying on newlines the parser should\r
+>> > use it's state to notice when one thread ends. \r
+>> > \r
+>> > Such a change could be used (privately) for human consumption -- allowing \r
+>> > free change of whitespace during inspection (in a debugging session or so).\r
+>> > Computer software should not rely (or suffer) from any additional\r
+>> > (or lack thereof) whitespace there is...\r
+>> > \r
+>> > ... or at least a really convicing argument for the chance needs to\r
+>> > be presented (before "restricting" the json output notmuch spits out).\r
+>> \r
+>> Given a JSON parser that only knows how to parse complete JSON\r
+>> expressions, it's potentially very inefficient to keep attempting to\r
+>> parse something when you don't know if it's complete.  The newlines\r
+>> provide an in-band framing so the consumer knows when there's a\r
+>> complete object to be parsed.\r
+>> \r
+>> In effect, this defines a super-protocol of JSON that's compatible\r
+>> with standard JSON, but easy to incrementally parse.\r
+>> \r
+>> That said, just this weekend I implemented JSON-based search with\r
+>> incremental JSON parsing and I took a slightly different approach.  I\r
+>> still put framing into the newlines of the search results, but rather\r
+>> than rely on it for correctness, the consumer uses it as an\r
+>> optimization that only hints that a complete JSON expression is\r
+>> probably available.  If the expression turns out to be incomplete,\r
+>> that's okay.\r
+>> \r
+>> I considered building a fully-incremental JSON parser that never\r
+>> backtracks by more than a token, which would eliminate even the cost\r
+>> of reparsing, but if we do move to S-expressions (which I think we\r
+>> should), we want to let Emacs' C implementation do as much of the\r
+>> parsing as possible, and the only thing we can do with that is read a\r
+>> complete expression.\r
+>\r
+> Actually, I take that back.  While we can't do fast incremental\r
+> S-expression parsing, `parse-partial-sexp' can tell us incrementally\r
+> (and probably very quickly) *if* there's a complete expression ready\r
+> to parse, so we could avoid calling into the parser at all unless it\r
+> would succeed.\r
+>\r
+> I'll try this out in my incremental JSON parser and see how well it\r
+> works.\r
+\r
+I played a bit with parse-partial-sexp (and sexp-at-point) and it looks\r
+like this really could work. IMO the things to be done could be\r
+\r
+1) add --format=sexp support to notmuch cli\r
+2) add tests for that (I can do some tests)\r
+3) review those patches (I will definitely be one reviewer)\r
+4) convert emacs to use --format=sexp everywhere it now uses --format=json,\r
+   (is it then basically s/(json-read)/(sexp-at-point)/ ?) and adjust tests.\r
+5) review those patches (I will definitely be one reviewer)\r
+6) add support to commands lines like \r
+   'notmuch search --output=sexp --sort=oldest-first tag:unread' ...\r
+   (even I can do that) (of course --output=json would work too as expected)\r
+7) review...\r
+8) convert emacs notmuch search to use that syntax and incrementally\r
+   display progress.\r
+9) review...\r
+\r
+This means that we would drop adding new features using json output in\r
+emacs mua and concentrate using sexps wherever applicable.\r
+\r
+(during this we should be able to determine whether those framing newlines\r
+ are needed or not)\r
+\r
+Tomi\r
+\r
+PS: A week ago I also did some experiments how notmuch cli could spit sexp\r
+output using current json formatters -- just naiively copying those and\r
+modifying would result like 99% of copy-paste and 1% of changes. I got some\r
+initial thoughts how thihgs could be done but luckily Peter & Austin are\r
+ahead of me -- I now just eagerly wait for patches to be reviewed :D\r