From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 4E267279 for ; Sat, 25 Feb 2017 06:23:22 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-io0-f182.google.com (mail-io0-f182.google.com [209.85.223.182]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 72C01157 for ; Sat, 25 Feb 2017 06:23:21 +0000 (UTC) Received: by mail-io0-f182.google.com with SMTP id 25so3575381iom.3 for ; Fri, 24 Feb 2017 22:23:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bittorrent-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=rsdaM0G3TpdvudIg/V3pGiqZdEmzDK8f8gTsA26DxxI=; b=GDOTpbPWqP08ceqbmEzDR/uhSjzn7Sfxl49XZB1QqCB+ohYYYVdX5t/R+aiEV3FFNE VurnaN07OI8WYtEAriLaWuIBAq1TUB8pGD3NMMdo0YIsLOuhW8d1kvOMHARnV5qCCkcK dQV+IuGUuqoRPViitx4StVniJqNONwQcKs7d53lJGTPmVBd2zhsF/8leQ+8+XPr0XGgy cwHKFMeOJtHRffYvGgDbZnSPHCPjbyv1S6P3P8ab4ppd2CgxYF/ChA4C1V8wVcBkYEjk tzfYPtrgpP97h6KZ9kTk0olZcmz2tCFHUUdpzHHvsNx9tbFH0WfABsQUznv/V4+fIgn7 XtyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=rsdaM0G3TpdvudIg/V3pGiqZdEmzDK8f8gTsA26DxxI=; b=iTwMFOPmRZJ62A+PbO3k2iBb9kizYyiwotysHxWUk+p0zzG8KPwU6CS/p2EG681yum PGFlL8UEpX5kmwMZ+7RBcZ1RyWBxPvGMKt9YnhHH+uRQSWJi53Nh0eDhk1IJfyF7fBBc Baj0KckglOOXSgKgs8fsqXmuCSufIpwSjWCg/mGeLoWzLohq5OenyIBejbc5kTjg2bpd Q3zmlAobbDk+6wEtpdLP4MYhSIUGOg7OgchbAoODf1Z5gYmJG60OzaR4LqL6FdQOjqEM 3rsUolq8M3nsXd4py6GygJ4L0acgz+IaNc6NbDBTAptW9fI9VndTE5FEGbU/c00Qlyso MAWA== X-Gm-Message-State: AMke39mykzR9FsMtllTSszdcAKGUDzz1PMYH4WCnmZkkiDJKc4mY8Tk9gxBxUEW9QKfX7CJDg+TGBS3tYgjSrIJ8 X-Received: by 10.107.15.70 with SMTP id x67mr5646511ioi.103.1488003800629; Fri, 24 Feb 2017 22:23:20 -0800 (PST) MIME-Version: 1.0 Received: by 10.36.73.150 with HTTP; Fri, 24 Feb 2017 22:23:20 -0800 (PST) In-Reply-To: <20170225041202.GA11152@savin.petertodd.org> References: <20170223235105.GA28497@savin.petertodd.org> <20170224010943.GA29218@savin.petertodd.org> <20170224025811.GA31911@savin.petertodd.org> <20170224031531.GA32118@savin.petertodd.org> <20170224043613.GA32502@savin.petertodd.org> <20170225041202.GA11152@savin.petertodd.org> From: Bram Cohen Date: Fri, 24 Feb 2017 22:23:20 -0800 Message-ID: To: Peter Todd Content-Type: multipart/alternative; boundary=001a113ed7fef638b9054954e147 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HTML_MESSAGE, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Bitcoin Protocol Discussion Subject: Re: [bitcoin-dev] A Better MMR Definition X-BeenThere: bitcoin-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Bitcoin Protocol Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Feb 2017 06:23:22 -0000 --001a113ed7fef638b9054954e147 Content-Type: text/plain; charset=UTF-8 On Fri, Feb 24, 2017 at 8:12 PM, Peter Todd wrote: > > So to be clear, what you're proposing there is to use the insertion order > as > the index - once you go that far you've almost entirely re-invented my > proposal! > I'm not 'proposing' this, I'm saying it could be done simply but I'm skeptical of the utility. Probably the most compelling argument for it is that the insertion indexed values are much smaller so they can be compacted down a lot resulting in using less memory and more locality and fewer hashes, but your implementation doesn't take advantage of that. > Your merkle-set implementation is 1500 lines of densely written Python The reference implementation which is included in those 1500 lines is less than 300 lines and fairly straightforward. The non-reference implementation always behaves semantically identically to the reference implementation, it just does so faster and using less memory. > with > almost no comments, The comments at the top explain both the proof format and the in-memory data structures very precisely. The whole codebase was reviewed by a coworker of mine and comments were added explaining the subtleties which tripped him up. > and less than a 100 lines of (also uncommented) tests. Those tests get 98% code coverage and extensively hit not only the lines of code but the semantic edge cases as well. The lines which aren't hit are convenience functions and error conditions of the parsing code for when it's passed bad data. > By > comparison, my Python MMR implementation is 300 lines of very readable > Python > with lots of comments, a 200 line explanation at the top, and 200 lines of > (commented) tests. Yet no-one is taking the (still considerable) effort to > understand and comment on my implementation. :) > Given that maaku's Merkle prefix trees were shelved because of performance problems despite being written in C and operating in basically the same way as your code and my reference code, it's clear that non-optimized Python won't be touching the bitcoin codebase any time soon. > > Fact is, what you've written is really daunting to review, and given it's > not > in the final language anyway, it's unclear what basis to review it on > anyway. It should reviewed based on semantic correctness and performance. Performance can only be accurately and convincingly determined by porting to C and optimizing it, which mostly involves experimenting with different values for the two passed in magic numbers. > I > suspect you'd get more feedback if the codebase was better commented, in a > production language, and you have actual real-world benchmarks and > performance > figures. > Porting to C should be straightforward. Several people have already expressed interest in doing so, and it's written in intentionally C-ish Python, resulting in some rather odd idioms which is a bit part of why you think it looks 'dense'. A lot of that weird offset math should be much more readable in C because it's all structs and x.y notation can be used instead of adding offsets. > In particular, while at the top of merkle_set.py you have a list of > advantages, > and a bunch of TODO's, you don't explain *why* the code has any of these > advantages. To figure that out, I'd have to read and understand 1500 lines > of > densely written Python. Without a human-readable pitch, not many people are > going to do that, myself included. > It's all about cache coherence. When doing operations it pulls in a bunch of things which are near each other in memory instead of jumping all over the place. The improvements it gets should be much greater than the ones gained from insertion ordering, although the two could be accretive. --001a113ed7fef638b9054954e147 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On F= ri, Feb 24, 2017 at 8:12 PM, Peter Todd <pete@petertodd.org> wrote:

So to be clear, what you're proposing there is to use the insert= ion order as
the index - once you go that far you've almost entirely re-invented my<= br> proposal!

I'm not 'proposing= 9; this, I'm saying it could be done simply but I'm skeptical of th= e utility. Probably the most compelling argument for it is that the inserti= on indexed values are much smaller so they can be compacted down a lot resu= lting in using less memory and more locality and fewer hashes, but your imp= lementation doesn't take advantage of that.
=C2=A0
Your merkle-set implementation is 1500 lines of d= ensely written Python

The reference impleme= ntation which is included in those 1500 lines is less than 300 lines and fa= irly straightforward. The non-reference implementation always behaves seman= tically identically to the reference implementation, it just does so faster= and using less memory.
=C2=A0
and less than a 100 lines of (also unco= mmented) tests.

Those tests get 98% code co= verage and extensively hit not only the lines of code but the semantic edge= cases as well. The lines which aren't hit are convenience functions an= d error conditions of the parsing code for when it's passed bad data.
=C2=A0
By
comparison, my Python MMR implementation is 300 lines of very readable Pyth= on
with lots of comments, a 200 line explanation at the top, and 200 lines of<= br> (commented) tests. Yet no-one is taking the (still considerable) effort to<= br> understand and comment on my implementation. :)

Given that maaku's Merkle prefix trees were shelved because of= performance problems despite being written in C and operating in basically= the same way as your code and my reference code, it's clear that non-o= ptimized Python won't be touching the bitcoin codebase any time soon.= =C2=A0
=C2=A0

Fact is, what you've written is really daunting to review, and given it= 's not
in the final language anyway, it's unclear what basis to review it on a= nyway.

It should reviewed based on semantic= correctness and performance. Performance can only be accurately and convin= cingly determined by porting to C and optimizing it, which mostly involves = experimenting with different values for the two passed in magic numbers.
=C2=A0
I
suspect you'd get more feedback if the codebase was better commented, i= n a
production language, and you have actual real-world benchmarks and performa= nce
figures.

Porting to C should be straigh= tforward. Several people have already expressed interest in doing so, and i= t's written in intentionally C-ish Python, resulting in some rather odd= idioms which is a bit part of why you think it looks 'dense'. A lo= t of that weird offset math should be much more readable in C because it= 9;s all structs and x.y notation can be used instead of adding offsets.
=C2=A0
In particular, while at t= he top of merkle_set.py you have a list of advantages,
and a bunch of TODO's, you don't explain *why* the code has any of = these
advantages. To figure that out, I'd have to read and understand 1500 li= nes of
densely written Python. Without a human-readable pitch, not many people are=
going to do that, myself included.

It&#= 39;s all about cache coherence. When doing operations it pulls in a bunch o= f things which are near each other in memory instead of jumping all over th= e place. The improvements it gets should be much greater than the ones gain= ed from insertion ordering, although the two could be accretive.
=
--001a113ed7fef638b9054954e147--