New submission from INADA Naoki: PyDict_GetItemString() is heavily used, especially from keyword argument parsing. Current implementation creates temporary string for key object. This patch avoid the temporary key string when passed C string is ASCII.
This benchmark is based on a8563ef0eb8a, so PyDict_GetItemString() calls for parsing positional arguments is reduced already. $ ../python -m perf compare_to -G --min-speed 2 default.json patched.json Slower (1): - scimark_lu: 430 ms +- 21 ms -> 446 ms +- 23 ms: 1.04x slower (+4%) Faster (11): - telco: 24.2 ms +- 0.4 ms -> 21.8 ms +- 0.7 ms: 1.11x faster (-10%) - xml_etree_parse: 315 ms +- 17 ms -> 302 ms +- 14 ms: 1.04x faster (-4%) - logging_simple: 31.6 us +- 0.3 us -> 30.4 us +- 0.3 us: 1.04x faster (-4%) - mako: 41.6 ms +- 0.7 ms -> 40.3 ms +- 0.4 ms: 1.03x faster (-3%) - logging_format: 36.5 us +- 0.3 us -> 35.5 us +- 0.4 us: 1.03x faster (-3%) - float: 297 ms +- 4 ms -> 289 ms +- 4 ms: 1.03x faster (-3%) - scimark_monte_carlo: 276 ms +- 10 ms -> 269 ms +- 7 ms: 1.02x faster (-2%) - regex_effbot: 5.31 ms +- 0.37 ms -> 5.19 ms +- 0.06 ms: 1.02x faster (-2%) - pickle_pure_python: 1.32 ms +- 0.02 ms -> 1.29 ms +- 0.02 ms: 1.02x faster (-2%) - scimark_sor: 525 ms +- 9 ms -> 514 ms +- 8 ms: 1.02x faster (-2%) - richards: 180 ms +- 3 ms -> 176 ms +- 2 ms: 1.02x faster (-2%) Benchmark hidden because not significant (52): ... Performance difference of telco is bit surprising. Profiler shows the difference is from `print(t, file=outfil)` (here: https://github.com/python/performance/blob/master/performance/benchmarks/bm_telco.py#L79 ) Until most common builtin functions are converted to FASTCALL, this patch has significant performance gain. ---------- components: Interpreter Core files: dict_getitemascii.patch keywords: patch messages: 285631 nosy: inada.naoki priority: normal severity: normal status: open title: dict: Optimize PyDict_GetItemString() type: performance versions: Python 3.7 Added file: http://bugs.python.org/file46313/dict_getitemascii.patch _______________________________________ Python tracker <[email protected]> <http://bugs.python.org/issue29295> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
