Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make docstring in C const #80822

Closed
methane opened this issue Apr 16, 2019 · 3 comments
Closed

make docstring in C const #80822

methane opened this issue Apr 16, 2019 · 3 comments
Labels
3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@methane
Copy link
Member

methane commented Apr 16, 2019

BPO 36641
Nosy @vstinner, @methane, @serhiy-storchaka
PRs
  • bpo-36641: Add "const" to PyDoc_VAR macro #12854
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-04-16.23:41:02.942>
    created_at = <Date 2019-04-16.12:05:17.472>
    labels = ['interpreter-core', '3.8']
    title = 'make docstring in C const'
    updated_at = <Date 2019-04-16.23:41:02.942>
    user = 'https://github.com/methane'

    bugs.python.org fields:

    activity = <Date 2019-04-16.23:41:02.942>
    actor = 'methane'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-04-16.23:41:02.942>
    closer = 'methane'
    components = ['Interpreter Core']
    creation = <Date 2019-04-16.12:05:17.472>
    creator = 'methane'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36641
    keywords = ['patch']
    message_count = 3.0
    messages = ['340333', '340335', '340371']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'methane', 'serhiy.storchaka']
    pr_nums = ['12854']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue36641'
    versions = ['Python 3.8']

    @methane
    Copy link
    Member Author

    methane commented Apr 16, 2019

    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

    @methane methane added 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Apr 16, 2019
    @methane
    Copy link
    Member Author

    methane commented Apr 16, 2019

    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

    @methane
    Copy link
    Member Author

    methane commented Apr 16, 2019

    New changeset 926b0cb by Inada Naoki in branch 'master':
    bpo-36641: Add "const" to PyDoc_VAR macro (GH-12854)
    926b0cb

    @methane methane closed this as completed Apr 16, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant