New submission from INADA Naoki:

add_methods(), add_members(), and add_getset() creates PyUnicode from C string 
3 times, and calls PyUnicode_InternInplace 2 times.

1. PyDict_GetItemString() at first. (PyUnicode_FromString() is called).
2. In middle, descr_new() calls PyUnicode_InternFromString().
3. PyDict_SetItemString() at last. (creates unicode and intern it).

Skipping (2) is require adding new private APIs to pass PyUnicodeObject.
But I don't think it worth enough. (I'll try it later.)
So this patch only remove last temporary unicode.
(3 PyUnicode_FromString + 2 PyUnicode_InternInplace) becomes (2 
PyUnicode_FromString + 2 PyUnicode_InternInplace).

It seems ~1% startup speedup (without site).

  $ ./python -m performance.benchmarks.bm_python_startup --no-site
  default: python_startup_no_site: Median +- std dev: 12.7 ms +- 0.1 ms
  patched: python_startup_no_site: Median +- std dev: 12.6 ms +- 0.1 ms

While speedup is small, this patch removes time to think "How large this
overhead of GetItemString + SetItemString pair?" while reading code :)

Additionally, this patch removes this comment in PyDict_SetItemString:

  -    PyUnicode_InternInPlace(&kv); /* XXX Should we really? */

SetItemString is used to add something to namespace.
Changing this behavior affects too widely.  So we should do it.

----------
assignee: inada.naoki
components: Interpreter Core
files: descr-remove-getitemstring.patch
keywords: patch
messages: 286394
nosy: inada.naoki
priority: normal
severity: normal
status: open
title: Reduce temporary unicode object while adding descriptors
versions: Python 3.7
Added file: http://bugs.python.org/file46441/descr-remove-getitemstring.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29383>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to