frozendict: an experiment

Inada Naoki songofacandy at gmail.com
Sat Jul 18 04:02:28 EDT 2020


On Sat, Jul 18, 2020 at 7:05 AM Marco Sulla
<Marco.Sulla.Python at gmail.com> wrote:
>
> >
> > But when frozendicts are merged?
> > I think there is a very little chance.
>
> frozendicts could be used for kwargs:
>
> f(a=1, b=2)
> # some code
> f(a=1, b=2)
>
> For what I know, CPython uses PyDictObject for kwargs. Since dicts are
> mutable, it's a problem to cache them properly.
>

On caller side, Python doesn't use dict at all.
On callee side, dict is used for `**kwargs`.  But changing it to frozendict is
backward incompatible change.


> On Fri, 17 Jul 2020 at 04:13, Inada Naoki <songofacandy at gmail.com> wrote:
> > I'm OK to all combined dict for frozen dict.  But I think key-sharing is still
> > interesting optimization for frozen dict. And supporting key-sharing dict
> > is much easier for frozendict than for mutable dict.
>
> Yes, I think the same.
>
> On Fri, 17 Jul 2020 at 04:13, Inada Naoki <songofacandy at gmail.com> wrote:
> > Then, there is no reason to not support the view for frozendict?
>
> I didn't say to not support views... I said that "real objects", that
> implement the dictview API, could be returned by frozendict.keys()
> etc.

It will cause performance penalty.  Currently, `for k,v in d.items()`
doesn't create
temporary list or set-like.
I think using "real object" is not good performance optimization.

Regards,
-- 
Inada Naoki  <songofacandy at gmail.com>


More information about the Python-list mailing list