classification
Title: make docstring in C const
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: inada.naoki, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2019-04-16 12:05 by inada.naoki, last changed 2019-04-16 23:41 by inada.naoki. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12854 merged inada.naoki, 2019-04-16 12:19
Messages (3)
msg340333 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-04-16 12:05
In most case, docstring in C is constant.
Can we add "const"?  If we can, it can avoid allocating and copying several KBs.

--- a/Include/pymacro.h
+++ b/Include/pymacro.h
@@ -69,4 +69,4 @@
 /* Define macros for inline documentation. */
-#define PyDoc_VAR(name) static char name[]
+#define PyDoc_VAR(name) static const char name[]
 #define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
 #ifdef WITH_DOC_STRINGS


Some drastic impacts:

before:
   text    data     bss     dec     hex filename
 110446   57371      96  167913   28fe9 Modules/posixmodule.o
  91937   32236     208  124381   1e5dd build/temp.linux-x86_64-3.8/home/inada-n/work/python/cpython/Modules/_decimal/_decimal.o
  61070   31534     472   93076   16b94 build/temp.linux-x86_64-3.8/home/inada-n/work/python/cpython/Modules/_cursesmodule.o


after:
$ size **/*.o
   text    data     bss     dec     hex filename
 150761   17064      96  167921   28ff1 Modules/posixmodule.o
 115213    8976     208  124397   1e5ed build/temp.linux-x86_64-3.8/home/inada-n/work/python/cpython/Modules/_decimal/_decimal.o
  86878    5736     472   93086   16b9e build/temp.linux-x86_64-3.8/home/inada-n/work/python/cpython/Modules/_cursesmodule.o
msg340335 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-04-16 12:12
Without any configure options:

$ size python python-const
   text    data     bss     dec     hex filename
2980860  448880  131672 3561412  3657c4 python
3185372  244464  131664 3561500  36581c python-const
msg340371 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-04-16 23:39
New changeset 926b0cb5f688808dc11448a0bf3e452d1b92c232 by Inada Naoki in branch 'master':
bpo-36641: Add "const" to PyDoc_VAR macro (GH-12854)
https://github.com/python/cpython/commit/926b0cb5f688808dc11448a0bf3e452d1b92c232
History
Date User Action Args
2019-04-16 23:41:02inada.naokisetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-04-16 23:39:58inada.naokisetmessages: + msg340371
2019-04-16 12:54:39xtreaksetnosy: + vstinner
2019-04-16 12:40:53xtreaksetnosy: + serhiy.storchaka
2019-04-16 12:19:38inada.naokisetkeywords: + patch
stage: patch review
pull_requests: + pull_request12780
2019-04-16 12:12:04inada.naokisetmessages: + msg340335
2019-04-16 12:05:17inada.naokicreate