[issue41835] Speed up dict vectorcall creation using keywords

2020-11-02 Thread Inada Naoki
Inada Naoki added the comment: While this is an interesting optimization, the gain is not enough. I close this issue for now. @Marco Sulla Optimizing dict is a bit hard job. If you want to continue, I have an idea: `dict(zip(keys, row))` is common use case. It is used by asdict() in datacalss,

[issue41835] Speed up dict vectorcall creation using keywords

2020-11-02 Thread Inada Naoki
Inada Naoki added the comment: And bench_kwcall.py is a microbenchmark for _PyEval_EvalCode. $ cpython/release/python -m pyperf compare_to master.json kwcall-nodup.json kwcall-3: Mean +- std dev: [master] 192 us +- 2 us -> [kwcall-nodup] 175 us +- 1 us: 1.09x faster (-9%) kwcall-6: Mean +- s

[issue41835] Speed up dict vectorcall creation using keywords

2020-11-02 Thread Inada Naoki
Inada Naoki added the comment: Short result (minspeed=2): Slower (4): - unpack_sequence: 65.2 ns +- 1.3 ns -> 69.2 ns +- 0.4 ns: 1.06x slower (+6%) - unpickle_list: 5.21 us +- 0.04 us -> 5.44 us +- 0.02 us: 1.04x slower (+4%) - chameleon: 9.80 ms +- 0.08 ms -> 10.0 ms +- 0.1 ms: 1.02x slower (

[issue41835] Speed up dict vectorcall creation using keywords

2020-11-02 Thread Inada Naoki
Inada Naoki added the comment: > I did PGO+LTO... --enable-optimizations --with-lto I'm sorry about that. PGO+LTO *reduce* noises, but there are still noises. And unpack_sequence is very fragile. I tried your branch again, and unpack_sequence is 10% *slower* than master branch. I am running

[issue41835] Speed up dict vectorcall creation using keywords

2020-11-02 Thread Inada Naoki
Change by Inada Naoki : -- pull_requests: +22023 stage: -> patch review pull_request: https://github.com/python/cpython/pull/23106 ___ Python tracker ___ _

[issue41835] Speed up dict vectorcall creation using keywords

2020-11-01 Thread Marco Sulla
Marco Sulla added the comment: I did PGO+LTO... --enable-optimizations --with-lto -- ___ Python tracker ___ ___ Python-bugs-list ma

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-31 Thread Inada Naoki
Inada Naoki added the comment: > It should *not* be affected by the change. Anyway, I run the bench other 10 > times, and the lowest value with the CPython code without the PR is not lower > than 67.7 ns. With the PR, it reaches 53.5 ns. And I do not understand why. The benchmark is very aff

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-31 Thread Marco Sulla
Marco Sulla added the comment: Well, actually Serhiy is right, it does not seem that the macro benchs did show something significant. Maybe the code can be used in other parts of CPython, for example in _pickle, where dicts are loaded. But it needs also to expose, maybe internally only, dict

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-31 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Do not overestimate the importance of _PyStack_AsDict(). Most of calls (~90-95% or like) are with positional only arguments, and most of functions do not have var-keyword parameter. So efforts in last years were spent on optimizing common cases, in particu

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-31 Thread Inada Naoki
Inada Naoki added the comment: > Both changes add significant amount of code (100 and 85 lines > correspondingly). Even if they speed up a particular case of dict constructor > it is not common use case. You are right, but please wait. Marco is new contributor and he can write correct C cod

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-31 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Both changes add significant amount of code (100 and 85 lines correspondingly). Even if they speed up a particular case of dict constructor it is not common use case. I think that it would be better to reject these changes. They make maintenance harder, t

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-30 Thread Inada Naoki
Inada Naoki added the comment: unpack_sequence is very sensitive benchmark. Speed is dramatically changed by code alignment. PGO+LTO will reduce the noise, but we see noise always. I believe there is no significant performance change in macro benchmarks when optimizing this part. Not signif

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-30 Thread Marco Sulla
Marco Sulla added the comment: Well, following your example, since split dicts seems to be no more supported, I decided to be more drastic. If you see the last push in PR 22346, I do not check anymore but always resize, so the dict is always combined. This seems to be especially good for the

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-24 Thread Marco Sulla
Marco Sulla added the comment: I commented out sqlalchemy in the requirements.txt in the pyperformance source code, and it worked. I had also to skip tornado: pyperformance run -r -b,-sqlalchemy_declarative,-sqlalchemy_imperative,-tornado_http -o ../perf_master.json This is my result: pyp

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-24 Thread Inada Naoki
Inada Naoki added the comment: I confirmed _PyDict_FromItems() can be used to optimize _PyStack_AsDict() too. See https://github.com/methane/cpython/pull/25 But I can not confirm significant performance gain from it too. -- ___ Python tracker

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-24 Thread Inada Naoki
Inada Naoki added the comment: @Marco Sulla > @methane: well, to be honest, I don't see much difference between the two > pulls. The major difference is that you merged insertdict_init in > dict_merge_init. Not only it but also some simplification which make 10% faster than GH-22346. > But

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-24 Thread Inada Naoki
Inada Naoki added the comment: @Mark.Shannon I had seen some speedup on tornado benchmark when I didn't use PGO+LTO. but it was noise. Now I use PGO+LTO. master vs PR-22909: $ ./python -m pyperf compare_to master-opt.json speedup_kw-opt.json -G --min-speed=1 Slower (11): - spectral_norm: 14

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-23 Thread Marco Sulla
Marco Sulla added the comment: @Mark.Shannon I tried to run pyperformance, but wheel does not work for Python 3.10. I get the error: AssertionError: would build wheel with unsupported tag ('cp310', 'cp310', 'linux_x86_64') -- ___ Python tracker

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-23 Thread Marco Sulla
Marco Sulla added the comment: @methane: well, to be honest, I don't see much difference between the two pulls. The major difference is that you merged insertdict_init in dict_merge_init. But I kept insertdict_init separate on purpose, because this function can be used in other future dedic

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-23 Thread Mark Shannon
Mark Shannon added the comment: Could we get a pyperformance benchmark run on this please? -- nosy: +Mark.Shannon ___ Python tracker ___ __

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-23 Thread Inada Naoki
Inada Naoki added the comment: @Marco Sulla Please take a look at GH-22909. It is simplified version of your PR. And I wrote another optimization based on it #42126. -- ___ Python tracker __

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-22 Thread Inada Naoki
Inada Naoki added the comment: Ok. Performance improvement comes from: a. Presizing b. Bypassing some checks in PyDict_SetItem c. Avoiding duplication check. (b) is relatively small so I tried to focus on (a) and (b). See GH-22909. In case of simple keyword arguments, it is 10% faster than G

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-22 Thread Inada Naoki
Change by Inada Naoki : -- keywords: +patch pull_requests: +21840 stage: -> patch review pull_request: https://github.com/python/cpython/pull/22909 ___ Python tracker ___

[issue41835] Speed up dict vectorcall creation using keywords

2020-10-22 Thread Marco Sulla
Marco Sulla added the comment: Another bench: python -m pyperf timeit --rigorous "dict(ihinvdono='doononon', gowwondwon='nwog', bdjbodbob='nidnnpn', nwonwno='vndononon', dooodbob='iohiwipwgpw', doidonooq='ndwnnpnpnp', fndionqinqn='ndjboqoqjb', nonoeoqgoqb='bdboboqbgoqeb', jdnvonvoddo='nvdjn

[issue41835] Speed up dict vectorcall creation using keywords

2020-09-23 Thread Marco Sulla
Marco Sulla added the comment: > `dict(**o)` is not common use case. Could you provide some other benchmarks? You can do python -m timeit -n 200 "dict(key1=1, key2=2, key3=3, key4=4, key5=5, key6=6, key7=7, key8=8, key9=9, key10=10)" or with pyperf. In this case, since the dict is littl

[issue41835] Speed up dict vectorcall creation using keywords

2020-09-22 Thread Inada Naoki
Inada Naoki added the comment: I have a Linux desktop machine for benchmarking & profiling in my office. But the machine is offline and I am working from home several weeks. So please wait several weeks until I confirm your branch. > This change speeds up the code up to a 30%. Tested with: >

[issue41835] Speed up dict vectorcall creation using keywords

2020-09-22 Thread Marco Sulla
New submission from Marco Sulla : I've done a PR that speeds up the vectorcall creation of a dict using keyword arguments. The PR in practice creates a insertdict_init(), a specialized version of insertdict. I quote the comment to the function: Same to insertdict but specialized for inserting