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

Improve the bytecode for mapping patterns #88677

Closed
brandtbucher opened this issue Jun 26, 2021 · 3 comments
Closed

Improve the bytecode for mapping patterns #88677

brandtbucher opened this issue Jun 26, 2021 · 3 comments
Assignees
Labels
3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@brandtbucher
Copy link
Member

BPO 44511
Nosy @markshannon, @brandtbucher
PRs
  • bpo-44511: Improve the bytecode for class and mapping patterns #26922
  • bpo-44511: Remove Programs/_freeze_importlib #29357
  • 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 = 'https://github.com/brandtbucher'
    closed_at = None
    created_at = <Date 2021-06-26.00:12:00.030>
    labels = ['interpreter-core', '3.11']
    title = 'Improve the bytecode for mapping patterns'
    updated_at = <Date 2021-11-02.00:29:19.363>
    user = 'https://github.com/brandtbucher'

    bugs.python.org fields:

    activity = <Date 2021-11-02.00:29:19.363>
    actor = 'brandtbucher'
    assignee = 'brandtbucher'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2021-06-26.00:12:00.030>
    creator = 'brandtbucher'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44511
    keywords = ['patch']
    message_count = 2.0
    messages = ['396533', '405079']
    nosy_count = 2.0
    nosy_names = ['Mark.Shannon', 'brandtbucher']
    pr_nums = ['26922', '29357']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44511'
    versions = ['Python 3.11']

    @brandtbucher
    Copy link
    Member Author

    The generated bytecode for mapping patterns is more complicated than it needs to be:

    • Matching sub-patterns involves indexing into a tuple of values in order to extract them. We already know the size of this tuple at compile-time, so we can just unpack it onto the stack instead.

    • COPY_DICT_WITHOUT_KEYS isn't used anywhere else, and can be emulated with existing, smaller instructions (albeit using quite a few of them).

    • MATCH_KEYS doesn't need to push a boolean indicating match / no match. It already pushes None on no match, so following it with a simple DUP_TOP() + LOAD_CONST(None) + IS_OP(1) should suffice.

    These are mostly just refactoring opportunities... quick-and-dirty measurements of Lib/test_patma.py show no performance impact for these changes.

    @brandtbucher brandtbucher added the 3.11 only security fixes label Jun 26, 2021
    @brandtbucher brandtbucher self-assigned this Jun 26, 2021
    @brandtbucher brandtbucher added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.11 only security fixes labels Jun 26, 2021
    @brandtbucher brandtbucher self-assigned this Jun 26, 2021
    @brandtbucher brandtbucher added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jun 26, 2021
    @markshannon
    Copy link
    Member

    New changeset 82a662e by Brandt Bucher in branch 'main':
    bpo-44511: Improve the bytecode for class and mapping patterns (GH-26922)
    82a662e

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @kumaraditya303
    Copy link
    Contributor

    Fixed by #26922

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants