[issue37587] JSON loads performance improvement for long strings

2019-10-17 Thread Inada Naoki
Change by Inada Naoki : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue37587] JSON loads performance improvement for long strings

2019-10-17 Thread Inada Naoki
Inada Naoki added the comment: New changeset 9c11029bb41caab5576f354fbf808a5e91325bb0 by Inada Naoki in branch 'master': bpo-37587: json: Use _PyUnicodeWriter when scanning string. (GH-15591) https://github.com/python/cpython/commit/9c11029bb41caab5576f354fbf808a5e91325bb0 --

[issue37587] JSON loads performance improvement for long strings

2019-08-29 Thread Inada Naoki
Inada Naoki added the comment: @mpaolini I don't have enough time in these weeks. Would you try PR-15591? I confirmed up to 4x speedup. But I'm afraid about there is performance regression in simple cases. -- ___ Python tracker

[issue37587] JSON loads performance improvement for long strings

2019-08-29 Thread Inada Naoki
Change by Inada Naoki : -- pull_requests: +15267 pull_request: https://github.com/python/cpython/pull/15591 ___ Python tracker ___

[issue37587] JSON loads performance improvement for long strings

2019-08-15 Thread Marco Paolini
Marco Paolini added the comment: ujson (https://github.com/esnme/ultrajson) instead is faster when decoding non-ascii in the same example above, so it is likely there is room for improvement... -- ___ Python tracker

[issue37587] JSON loads performance improvement for long strings

2019-08-15 Thread Marco Paolini
Marco Paolini added the comment: ops sorry here's the right commands python -m pyperf timeit -s 'import json;' -s 'c = "a"; s = json.dumps(c * (2**10 // (len(json.dumps(c)) - 2)))' 'json.loads(s)' -o ascii2k.json python -m pyperf timeit -s 'import json;' -s 'c = "€"; s = json.dumps(c *

[issue37587] JSON loads performance improvement for long strings

2019-08-15 Thread Marco Paolini
Marco Paolini added the comment: also worth noting escape sequences for non-ascii characters are slower, even when encoded length is the same. python -m pyperf timeit -s 'import json;' -s 'c = "€"; s = json.dumps(c * (2**10 // len(json.dumps(c)) - 2))' 'json.loads(s)' -o nonascii2k.json

[issue37587] JSON loads performance improvement for long strings

2019-08-15 Thread Marco Paolini
Marco Paolini added the comment: I also confirm Inada's patch further improves performance! All my previous benchmarks were done with gcc and PGO optimizations performed only with test_json task... maybe this explains the weird results? I tested the performance of new master

[issue37587] JSON loads performance improvement for long strings

2019-08-08 Thread Inada Naoki
Inada Naoki added the comment: New changeset 2a570af12ac5e4ac5575a68f8739b31c24d01367 by Inada Naoki in branch 'master': bpo-37587: optimize json.loads (GH-15134) https://github.com/python/cpython/commit/2a570af12ac5e4ac5575a68f8739b31c24d01367 --

[issue37587] JSON loads performance improvement for long strings

2019-08-05 Thread Inada Naoki
Inada Naoki added the comment: And I confirmed performance improvement by my patch (GH-15134) on all of 4 compilers. $ ./python -m pyperf timeit -s "import json; x = json.dumps({'k': '1' * 2 ** 20})" "json.loads(x)" old: 9211e2 new: 8a758f opt2: 284e47 gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0

[issue37587] JSON loads performance improvement for long strings

2019-08-05 Thread Inada Naoki
Change by Inada Naoki : -- pull_requests: +14873 pull_request: https://github.com/python/cpython/pull/15134 ___ Python tracker ___

[issue37587] JSON loads performance improvement for long strings

2019-08-05 Thread Inada Naoki
Inada Naoki added the comment: I tried without PGO and confirmed performance improved on GCC 7.2.0. No change on other compiler versions. $ ./python -m pyperf timeit -s "import json; x = json.dumps({'k': '1' * 2 ** 20})" "json.loads(x)" old: 9211e2 new: 8a758f gcc (Ubuntu 8.3.0-6ubuntu1)

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Inada Naoki
Inada Naoki added the comment: This issue is very compiler sensitive. Please don't report performance without compiler version and PGO option. Now I'm facing strange behavior. pyperf reports slower time (1ms) for PGO builds, although disasm looks good. But it's 2:30am already... Please wait

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Inada Naoki
Inada Naoki added the comment: I'm sorry, I was wrong. PGO did very nice job on all cases. gcc allocates `c` to register in the hot loop. -- ___ Python tracker ___

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Inada Naoki
Inada Naoki added the comment: I tested before, after, Steve's patch, and my patch with gcc 8.3.0 and PGO+LTO. https://gist.github.com/methane/f6077bd1b0b04d40a9c790d9ed670a44#file-gcc-8-3-0-pgo-md Surprisingly, there is no difference. Even my patch didn't help register allocation when PGO

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Steve Dower
Steve Dower added the comment: > compiler stores the `c` to stack every time The disassembly we looked at didn't do this, so it may just be certain compilers. Perhaps we can actually use the register keyword to help them out? :) Here's a slightly altered one that doesn't require rescanning

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Inada Naoki
Inada Naoki added the comment: Since scope of "c" is very wide, and there is even `` in the scope, compiler stores the `c` to stack every time on: c = PyUnicode_READ(kind, buf, next); That is the bottleneck. `if (strict && ...)` is not the bottleneck. My patch used a new variable with

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Marco Paolini
Marco Paolini added the comment: @steve.dower yes, that's what made me discard that experiment we did during the sprint. Ok will test your new patch soon -- ___ Python tracker

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Steve Dower
Steve Dower added the comment: Oh, we also need to capture "next"... but then again, since the success case is far more common, I'd be okay with scanning again to find it. -- ___ Python tracker

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Steve Dower
Steve Dower added the comment: While you're testing patches, can you try this version too? Py_UCS4 c = 0, minc = 0x20; for (next = end; next < len; next++) { c = PyUnicode_READ(kind, buf, next); if (c == '"' || c == '\\') { break;

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Inada Naoki
Inada Naoki added the comment: Wait... there is no benchmark for the "minimum change". I tested 4 compilers, and provide much better patch in https://bugs.python.org/issue37587#msg348114 -- ___ Python tracker

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread miss-islington
miss-islington added the comment: New changeset 9265a877426af4fa5c44cc8482e0198806889350 by Miss Islington (bot) in branch '3.8': bpo-37587: Make json.loads faster for long strings (GH-14752) https://github.com/python/cpython/commit/9265a877426af4fa5c44cc8482e0198806889350 -- nosy:

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Nick Coghlan
Nick Coghlan added the comment: I went ahead and merged the minimal PR and flagged it for backporting to 3.8 - it's an obviously beneficial change, that clearly does less work on each pass through the loop. Even if you are doing non-strict parsing of a string that consists entirely of

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread miss-islington
Change by miss-islington : -- pull_requests: +14783 pull_request: https://github.com/python/cpython/pull/15022 ___ Python tracker ___

[issue37587] JSON loads performance improvement for long strings

2019-07-30 Thread Nick Coghlan
Nick Coghlan added the comment: New changeset 8a758f5b99c5fc3fd32edeac049d7d4a4b7cc163 by Nick Coghlan (Marco Paolini) in branch 'master': bpo-37587: Make json.loads faster for long strings (GH-14752) https://github.com/python/cpython/commit/8a758f5b99c5fc3fd32edeac049d7d4a4b7cc163

[issue37587] JSON loads performance improvement for long strings

2019-07-29 Thread Marco Paolini
Marco Paolini added the comment: I forgot to mention, I was inspired by @christian.heimes 's talk at EuroPython 2019 https://ep2019.europython.eu/talks/es2pZ6C-introduction-to-low-level-profiling-and-tracing/ (thanks!) -- ___ Python tracker

[issue37587] JSON loads performance improvement for long strings

2019-07-29 Thread Marco Paolini
Marco Paolini added the comment: I am also working on a different patch that uses the "pcmpestri" SSE4 processor instruction, it looks like this for now. While at it I realized there is (maybe) another potential speedup: avoiding the ucs4lib_find_max_char we do for each chunk of the string

[issue37587] JSON loads performance improvement for long strings

2019-07-29 Thread Marco Paolini
Marco Paolini added the comment: On gcc, running the tests above, the only change that is relevant for speedup is switching around the strict check. Removing the extra MOV related to the outer "c" variable is not significant (at least on gcc and the few tests I did) Unfortunately I had to

[issue37587] JSON loads performance improvement for long strings

2019-07-23 Thread Steve Dower
Steve Dower added the comment: Marco has a newer patch with better performance that we came up with at the sprints, but apparently it hasn't been pushed yet. Hopefully he'll get that up soon and we can review it instead - the current PR wasn't as reliably good as initial testing suggested.

[issue37587] JSON loads performance improvement for long strings

2019-07-18 Thread Inada Naoki
Change by Inada Naoki : -- versions: -Python 3.6, Python 3.7, Python 3.8 ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue37587] JSON loads performance improvement for long strings

2019-07-18 Thread Inada Naoki
Inada Naoki added the comment: Some compilers produce inefficient code for PR-14752. I wrote another patch which is friendly to more compilers. $ perf record ./python -m pyperf timeit -s "import json; x = json.dumps({'k': '1' * 2 ** 20})" "json.loads(x)" # PR-14752 gcc-7 (Ubuntu

[issue37587] JSON loads performance improvement for long strings

2019-07-18 Thread Inada Naoki
Inada Naoki added the comment: > 1. remove the mov entirely. It is not needed inside the loop and it is only > needed later, outside the loop to access the variable How can we lazy "movDWORD PTR [rsp+0x44],eax"? -- nosy: +inada.naoki ___

[issue37587] JSON loads performance improvement for long strings

2019-07-14 Thread Steve Dower
Change by Steve Dower : -- nosy: +steve.dower ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37587] JSON loads performance improvement for long strings

2019-07-13 Thread Marco Paolini
Marco Paolini added the comment: Here's the real world example $ ls -hs events-100k.json 84M events-100k.json +---+-+-+ | Benchmark | vanilla-bpo-events-100k | patched-bpo-events-100k |

[issue37587] JSON loads performance improvement for long strings

2019-07-13 Thread Marco Paolini
Marco Paolini added the comment: Also on my real workload (loading 60GB jsonl file containing mostly strings) I measured a 10% improvement -- ___ Python tracker ___

[issue37587] JSON loads performance improvement for long strings

2019-07-13 Thread Marco Paolini
Change by Marco Paolini : -- nosy: +ezio.melotti, rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37587] JSON loads performance improvement for long strings

2019-07-13 Thread Marco Paolini
Change by Marco Paolini : -- keywords: +patch pull_requests: +14547 stage: -> patch review pull_request: https://github.com/python/cpython/pull/14752 ___ Python tracker ___

[issue37587] JSON loads performance improvement for long strings

2019-07-13 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue37587] JSON loads performance improvement for long strings

2019-07-13 Thread Marco Paolini
New submission from Marco Paolini : I analysed the performance of json.loads in one production workload we have. Spy-py tells me the majority of time is spent into C json module (see events.svg) Digging deeper, linux perf tells me hottest loop (where 20%+ of the time is spent) in