Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"The greatest warriors are the ones who fight for peace." -- Holly Near


devel / comp.lang.python / Re: Why operations between dict views return a set and not a frozenset?

SubjectAuthor
o Re: Why operations between dict views return a set and not aMarco Sulla

1
Re: Why operations between dict views return a set and not a frozenset?

<mailman.152.1641926999.3079.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16665&group=comp.lang.python#16665

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: Marco.Su...@gmail.com (Marco Sulla)
Newsgroups: comp.lang.python
Subject: Re: Why operations between dict views return a set and not a
frozenset?
Date: Tue, 11 Jan 2022 19:49:20 +0100
Lines: 78
Message-ID: <mailman.152.1641926999.3079.python-list@python.org>
References: <CABbU2U9EBev-MWb+5j=uUZJaYAtKHw+raAviOFpd50d9ojsA2w@mail.gmail.com>
<CAPTjJmoRm26RiPsfhSph_Zwj=gJFyDN47u3kcvxfQPSM+fTf1g@mail.gmail.com>
<CABbU2U9Pazu_yjdm8veY+VnsGLpq9axSEXmF-eJrTV3ZjHax3g@mail.gmail.com>
<CAPTjJmoW0gV0dp9W=m=taB5vFZ4yy+DwAj9H9OUH+qXDkzhmmw@mail.gmail.com>
<CABbU2U_EPGTgGkhiMLxg86o9-NyxLXc9jGLBE-qf8jnG4fM-Sw@mail.gmail.com>
<CAPTjJmq=_Fo9ArCu-r0wZB-70WL0AjOqWttGqb_TLT62HBPnfQ@mail.gmail.com>
<CABbU2U_cV2m=QoNG+6w2RvRR05pLuoEyYFk8GbLx6P2zqPQWgg@mail.gmail.com>
<CAPTjJmqJ+nZfO-T6bkCbSERVko2TbQP5g11y_oB0+ZgUx06cfw@mail.gmail.com>
<CABbU2U_d+Sj8naMwz8jWPbc2+2=z1EmoSRYwjnAeA9Dceg1F=g@mail.gmail.com>
<CAPTjJmqXv8C5ZbQKG21nbZsGGifk6J3yj1m1OH0C-OUKuM9gBQ@mail.gmail.com>
<CABbU2U-wosnDQhN4eMZZfvypJ=hMf7u9sfvVRDjtS8J8e7X11w@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de T5klQLeKt/IY8jBRLsiX3QQTScBsIsj7Qj2ZaBSYoD9A==
Return-Path: <elbarbun@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=oHiz4QWN;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '2022': 0.05; 'is.': 0.05;
'&gt;&gt;&gt;': 0.07; '(to': 0.07; 'subject:Why': 0.07;
'angelico': 0.09; 'cc:addr:python-list': 0.09; 'const': 0.09;
'fewer': 0.09; 'methods,': 0.09; 'received:209.85.219': 0.09;
'subject:between': 0.09; 'subject:not': 0.09; '&gt;': 0.14;
'url:mailman': 0.15; 'cc:name:python list': 0.16; 'chrisa': 0.16;
'dictionary,': 0.16; 'from:name:marco sulla': 0.16; 'happening.':
0.16; 'inviting': 0.16; 'iteration': 0.16; 'mean:': 0.16;
'received:209.85.219.180': 0.16; 'received:mail-
yb1-f180.google.com': 0.16; 'slow': 0.16; 'subject:operations':
0.16; 'tuple': 0.16; 'understand.': 0.16; 'wrote:': 0.16;
'values': 0.17; "can't": 0.17; 'thu,': 0.19; 'tue,': 0.19;
'cc:addr:python.org': 0.20; 'language': 0.21; 'maybe': 0.22;
"what's": 0.22; 'version': 0.23; 'url-ip:188.166.95.178/32': 0.25;
'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'cc:2**0':
0.25; 'url-ip:188.166/16': 0.25; '11,': 0.26; 'object': 0.26;
'function': 0.27; '>>>': 0.28; 'chris': 0.28; 'this?': 0.29;
'deep': 0.31; 'default': 0.31; 'url-ip:188/8': 0.31; 'think':
0.32; 'course.': 0.32; 'said,': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'skip:2 10': 0.32; 'but': 0.32; "i'm":
0.33; "didn't": 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'functions': 0.36; "it's": 0.37; 'received:209.85': 0.37; 'way':
0.38; 'received:209': 0.39; 'use': 0.39; 'wed,': 0.39; 'explain':
0.40; 'something': 0.40; 'try': 0.40; 'sorry': 0.60; 'skip:o 10':
0.61; 'simply': 0.63; 'everything': 0.63; "you'd": 0.64; 'skip:r
20': 0.64; 'down': 0.64; 'look': 0.65; 'less': 0.65; 'nearly':
0.67; 'before,': 0.69; 'you.': 0.71; 'more.': 0.82; 'assembly.':
0.84; 'difference.': 0.84; 'dis': 0.84; 'furthermore': 0.84;
'massive': 0.84; 'sulla': 0.84; 'assembly,': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=FbJe4VBZW26VHD2l0P8dtlD/YaL4E085679KRb8uBJs=;
b=oHiz4QWNzQkowpU6kBwFQ1D+kVfPZp2DpEF+YHf63KKEXwbmSYiCG8XpqnwRu+fYx3
3Xy5iGV0oWVXrb0IynoSrUtwKJPxFuFoFsL0WNHy+JDyamEH6oGC0efgjg9oYqkuWVHW
Dz734+Ziteqpaxbn9Ej8BHvKo88k/zIm9mZp50OhRojhYoS+jF9EyxEb5c2kxOE+kPxD
edqJXKMQpfIU4+ZkxkbUnGpCsFjGSyPWqTW0HtYI6S+E+9vh3w7Jr9pdrwHjCxc26v5s
u/ewPhD5xtkN1Kg9MV+mngynIMJNSYA+L+Z9mfdEdY1Hsb7gQ/i0CClfIi82QvKlt9qX
XR6A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=FbJe4VBZW26VHD2l0P8dtlD/YaL4E085679KRb8uBJs=;
b=PQzDXuBUppy1s28P/f9GlN/AslnQyqUlU0/PL35tp8v1xYY+w34KgB3CT+KgnGDTre
IFca49GtJZMg0yAzoDlAVwOBSpD/DM3d2BPGw92+smwJfeL+9guM/AWnLaxJT9Fn05Qq
Ck8ugvNhHcw9gqIVEpMJFdnOf4rS6FJTOKtcuIS7tVjtmP1nCFo/1zIUTTfkghny1DeJ
s7RhhzHEh/yQgVQIVPF6KV2dRyQP1Ouo/jouP19+2vhapan7qr4vZBZBGM2SakV/GCpV
voAZpSS0IP6y93LNBSS2Q1YIhfnHF3uHtsOU7Mq6U9xKMbnyFQ/ctFmmJ0Xveu5DSZro
PqFQ==
X-Gm-Message-State: AOAM530RYzC9cjklEb/ZupFMnwnQ0zQzelGHVzW4GWx0k/AnZyOClEe+
O39INCceHARrAL59REkyJ1Bd6imQMn+SX7JA14UWkwW6+8k=
X-Google-Smtp-Source: ABdhPJy9vPNEImqkmKyXdhgSYBFikQJfBE14p34KoBZpzOxscIyxaFK5TB4CnNZIdp9r1Y235o4F4wpy8Q9X8KCAZxQ=
X-Received: by 2002:a25:ad08:: with SMTP id y8mr2340473ybi.738.1641926996933;
Tue, 11 Jan 2022 10:49:56 -0800 (PST)
In-Reply-To: <CAPTjJmqXv8C5ZbQKG21nbZsGGifk6J3yj1m1OH0C-OUKuM9gBQ@mail.gmail.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CABbU2U-wosnDQhN4eMZZfvypJ=hMf7u9sfvVRDjtS8J8e7X11w@mail.gmail.com>
X-Mailman-Original-References: <CABbU2U9EBev-MWb+5j=uUZJaYAtKHw+raAviOFpd50d9ojsA2w@mail.gmail.com>
<CAPTjJmoRm26RiPsfhSph_Zwj=gJFyDN47u3kcvxfQPSM+fTf1g@mail.gmail.com>
<CABbU2U9Pazu_yjdm8veY+VnsGLpq9axSEXmF-eJrTV3ZjHax3g@mail.gmail.com>
<CAPTjJmoW0gV0dp9W=m=taB5vFZ4yy+DwAj9H9OUH+qXDkzhmmw@mail.gmail.com>
<CABbU2U_EPGTgGkhiMLxg86o9-NyxLXc9jGLBE-qf8jnG4fM-Sw@mail.gmail.com>
<CAPTjJmq=_Fo9ArCu-r0wZB-70WL0AjOqWttGqb_TLT62HBPnfQ@mail.gmail.com>
<CABbU2U_cV2m=QoNG+6w2RvRR05pLuoEyYFk8GbLx6P2zqPQWgg@mail.gmail.com>
<CAPTjJmqJ+nZfO-T6bkCbSERVko2TbQP5g11y_oB0+ZgUx06cfw@mail.gmail.com>
<CABbU2U_d+Sj8naMwz8jWPbc2+2=z1EmoSRYwjnAeA9Dceg1F=g@mail.gmail.com>
<CAPTjJmqXv8C5ZbQKG21nbZsGGifk6J3yj1m1OH0C-OUKuM9gBQ@mail.gmail.com>
 by: Marco Sulla - Tue, 11 Jan 2022 18:49 UTC

Ok... so I suppose, since you're inviting me to use dis and look at the
bytecode, that are you talking about constants in assembly, so const in C?
Sorry for the confusion, I'm not so skilled in C and I know nearly nothing
about assembly. Furthermore I never look at the bytecode of any language
before, so I simply didn't understand you.

I think this is what you mean:

>>> dis.dis("for _ in {1, 2}: pass")
1 0 SETUP_LOOP 12 (to 14)
2 LOAD_CONST 3 (frozenset({1, 2}))
4 GET_ITER
>> 6 FOR_ITER 4 (to 12)
8 STORE_NAME 0 (_)
10 JUMP_ABSOLUTE 6
>> 12 POP_BLOCK
>> 14 LOAD_CONST 2 (None)
16 RETURN_VALUE
>>> a = {1, 2}
>>> dis.dis("for _ in a: pass")
1 0 SETUP_LOOP 12 (to 14)
2 LOAD_NAME 0 (a)
4 GET_ITER
>> 6 FOR_ITER 4 (to 12)
8 STORE_NAME 1 (_)
10 JUMP_ABSOLUTE 6
>> 12 POP_BLOCK
>> 14 LOAD_CONST 0 (None)
16 RETURN_VALUE

On Tue, 11 Jan 2022 at 01:05, Chris Angelico <rosuav@gmail.com> wrote:

> On Tue, Jan 11, 2022 at 10:26 AM Marco Sulla
> <Marco.Sulla.Python@gmail.com> wrote:
> >
> > On Wed, 5 Jan 2022 at 23:02, Chris Angelico <rosuav@gmail.com> wrote:
> > >
> > > On Thu, Jan 6, 2022 at 8:01 AM Marco Sulla <
> Marco.Sulla.Python@gmail.com> wrote:
> > > >
> > > > On Wed, 5 Jan 2022 at 14:16, Chris Angelico <rosuav@gmail.com>
> wrote:
> > > > > That's an entirely invisible optimization, but it's more than just
> > > > > "frozenset is faster than set". It's that a frozenset or tuple can
> be
> > > > > stored as a function's constants, which is a massive difference.
> > > >
> > > > Can you explain this?
> > >
> > > Play around with dis.dis and timeit.
> >
> > ? I don't understand. You're talking about function constants. What
> > are they? I can't dig deep into something if I can't know what it is.
> > Maybe are you talking about function default values for parameters?
>
> No, I'm talking about constants. Every function has them.
>
> > Of course. You can use a proxy and slow down almost everything much
> > more. Or you can simply create a version of the mutable object with
> > fewer methods, as more or less frozenset is. I checked the
> > implementation, no fast iteration is implemented. I do not understand
> > why in `for x in {1, 2, 3}` the set is substituted by a frozenset.
>
> Constants. Like I said, play around with dis.dis, and explore what's
> already happening. A set can't be a constant, a frozenset can be.
> Constants are way faster than building from scratch.
>
> Explore. Play around. I'm not going to try to explain everything in detail.
>
> If you're delving into the details of the C implementation of the
> dictionary, I would have expected you'd already be familiar with the
> way that functions behave.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor