Skip to content

String literals are not interned if in a tuple #70336

Closed

Description

@serhiy-storchaka
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']

    Activity

    1. serhiy-storchaka commented on Jan 18, 2016

      @serhiy-storchaka
      MemberAuthor

      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.

    2. added
      interpreter-core
      on Jan 18, 2016
    3. added
      performance
      on Jan 19, 2016
    4. vstinner commented on Jan 19, 2016

      @vstinner
      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 :-)

    5. serhiy-storchaka commented on Sep 25, 2016

      @serhiy-storchaka
      MemberAuthor

      The patch is provided in bpo-27942.

    6. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      interpreter-coreperformance

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions