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

String literals are not interned if in a tuple #70336

Closed
serhiy-storchaka opened this issue Jan 18, 2016 · 3 comments
Closed

String literals are not interned if in a tuple #70336

serhiy-storchaka opened this issue Jan 18, 2016 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@serhiy-storchaka
Copy link
Member

BPO 26148
Nosy @brettcannon, @birkenfeld, @rhettinger, @ncoghlan, @vstinner, @benjaminp, @serhiy-storchaka, @1st1
Superseder
  • bpo-27942: Default value identity regression
  • 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 2016-09-25.10:44:49.457>
    created_at = <Date 2016-01-18.20:09:48.624>
    labels = ['interpreter-core', 'performance']
    title = 'String literals are not interned if in a tuple'
    updated_at = <Date 2016-09-25.10:44:49.456>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2016-09-25.10:44:49.456>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-09-25.10:44:49.457>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2016-01-18.20:09:48.624>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 26148
    keywords = []
    message_count = 3.0
    messages = ['258542', '258594', '277361']
    nosy_count = 8.0
    nosy_names = ['brett.cannon', 'georg.brandl', 'rhettinger', 'ncoghlan', 'vstinner', 'benjamin.peterson', 'serhiy.storchaka', 'yselivanov']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '27942'
    type = 'performance'
    url = 'https://bugs.python.org/issue26148'
    versions = ['Python 3.6']

    @serhiy-storchaka
    Copy link
    Member Author

    Usually string literals are interned. But not if they are a part of constant tuple.

    >>> def abc(): pass
    ... 
    >>> x = 'abc'
    >>> x is abc.__name__
    True
    >>> x = ('abc',)
    >>> x[0] is abc.__name__
    False

    This makes effect on namedtuples (bpo-25981). May make effect on __slots__ or other uses of constant tuples since searching a value in a tuple when values are not identical is a little slower that when they are identical.

    @serhiy-storchaka serhiy-storchaka added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 18, 2016
    @vstinner vstinner added the performance Performance or resource usage label Jan 19, 2016
    @vstinner
    Copy link
    Member

    FYI fatoptimizer has a more efficient algorithm to merge constants:
    http://fatoptimizer.readthedocs.org/en/latest/optimizations.html#comparison-with-the-peephole-optimizer

    It looks like it interns strings which are part of tuples. To be honest, I don't understand how it works, but it works :-)

    @serhiy-storchaka
    Copy link
    Member Author

    The patch is provided in bpo-27942.

    @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
    interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants