Re: frozendict: an experiment

2020-07-21 Thread Marco Sulla
On Tue, 21 Jul 2020 at 06:01, Inada Naoki wrote: > On Tue, Jul 21, 2020 at 5:07 AM Marco Sulla wrote: > > > > I just finished to improve the performance of frozendict creation. The > result is very promising. > > > > The speedup is about 30% for small dicts (8 items). For large dicts (1k > items

Re: frozendict: an experiment

2020-07-20 Thread Inada Naoki
On Tue, Jul 21, 2020 at 5:07 AM Marco Sulla wrote: > > I just finished to improve the performance of frozendict creation. The result > is very promising. > > The speedup is about 30% for small dicts (8 items). For large dicts (1k > items) is about 38% for dicts with only integers as keys and val

Re: frozendict: an experiment

2020-07-20 Thread Marco Sulla
I just finished to improve the performance of frozendict creation. The result is very promising. The speedup is about 30% for small dicts (8 items). For large dicts (1k items) is about 38% for dicts with only integers as keys and values, and 45% for dicts with only strings. There's also a little

Re: frozendict: an experiment

2020-07-18 Thread Inada Naoki
On Sun, Jul 19, 2020 at 6:38 AM Marco Sulla wrote: > > On Sat, 18 Jul 2020 at 10:02, Inada Naoki wrote: >> >> On Sat, Jul 18, 2020 at 7:05 AM Marco Sulla >> wrote: >> > For what I know, CPython uses PyDictObject for kwargs. Since dicts are >> > mutable, it's a problem to cache them properly. >>

Re: frozendict: an experiment

2020-07-18 Thread Marco Sulla
On Sat, 18 Jul 2020 at 10:02, Inada Naoki wrote: > On Sat, Jul 18, 2020 at 7:05 AM Marco Sulla > wrote: > > 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 s

Re: frozendict: an experiment

2020-07-18 Thread Inada Naoki
On Sat, Jul 18, 2020 at 7:05 AM Marco Sulla 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

Re: frozendict: an experiment

2020-07-17 Thread Marco Sulla
On Fri, 17 Jul 2020 at 04:13, Inada Naoki wrote: > > 3. many python internals uses a mapping proxy to a dict, to avoid its > > modification. A frozendict can be used instead. > > Are they used frequently in performance critical path? > Could you point some concrete examples? I searched a little i

Re: frozendict: an experiment

2020-07-16 Thread Inada Naoki
On Fri, Jul 17, 2020 at 2:16 AM Marco Sulla wrote: > > On Thu, 16 Jul 2020 at 06:11, Inada Naoki wrote: > > On Thu, Jul 16, 2020 at 2:32 AM Marco Sulla > > wrote: > > > Yes, but, instead of creating a view, you can create and cache the > > > pointer of a "real" object, that implements the dict v

Re: frozendict: an experiment

2020-07-16 Thread Marco Sulla
On Thu, 16 Jul 2020 at 06:11, Inada Naoki wrote: > On Thu, Jul 16, 2020 at 2:32 AM Marco Sulla > wrote: > > Yes, but, instead of creating a view, you can create and cache the > > pointer of a "real" object, that implements the dict view API. > > For example, keys for a frozendict could be an "ord

Re: frozendict: an experiment

2020-07-16 Thread Marco Sulla
On Wed, 15 Jul 2020 at 08:07, Inada Naoki wrote: > I don't think so. The view objects are useful when we need a set-like > operation. (e.g. `assert d.keys() == {"spam", "egg"}`) Yes, but, instead of creating a view, you can create and cache the pointer of a "real" object, that implements the dic

Re: frozendict: an experiment

2020-07-15 Thread Inada Naoki
On Thu, Jul 16, 2020 at 2:32 AM Marco Sulla wrote: > > On Wed, 15 Jul 2020 at 08:07, Inada Naoki wrote: > > I don't think so. The view objects are useful when we need a set-like > > operation. (e.g. `assert d.keys() == {"spam", "egg"}`) > > Yes, but, instead of creating a view, you can create an

Re: frozendict: an experiment

2020-07-14 Thread Inada Naoki
On Wed, Jul 15, 2020 at 2:01 AM Marco Sulla wrote: > > > Why do you think I do not need views to use the frozendict? > > I thought that is what make d.key(), d.items() etc work? > > Views for dict exist because dict is mutable. See this example: > > >>> d = {1: 2} > >>> keys = d.keys() > >>> d[2]

Re: frozendict: an experiment

2020-07-14 Thread Marco Sulla
On Mon, 13 Jul 2020 at 19:28, Barry Scott wrote: > > On 13 Jul 2020, at 03:20, Marco Sulla wrote: > > So why did I try to implement it? IMO, apart the considerations in PEP > > 416, a frozendict can be useful: > > > > - as a faster base for types.MutableMappingProxy > > - as a substitute of named

Re: frozendict: an experiment

2020-07-13 Thread Barry Scott
> On 13 Jul 2020, at 03:20, Marco Sulla wrote: > > TL;DR: I tried to implement in CPython a frozendict here: > https://github.com/Marco-Sulla/cpython > > Long explaining: > > What is a frozendict? It's an immutable dict. The type was proposed in > the past but rejected: https://www.python.or

frozendict: an experiment

2020-07-12 Thread Marco Sulla
TL;DR: I tried to implement in CPython a frozendict here: https://github.com/Marco-Sulla/cpython Long explaining: What is a frozendict? It's an immutable dict. The type was proposed in the past but rejected: https://www.python.org/dev/peps/pep-0416/ So why did I try to implement it? IMO, apart t