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

2to3 Slight Patch #47432

Closed
nedds mannequin opened this issue Jun 23, 2008 · 5 comments
Closed

2to3 Slight Patch #47432

nedds mannequin opened this issue Jun 23, 2008 · 5 comments
Labels
performance Performance or resource usage topic-2to3

Comments

@nedds
Copy link
Mannequin

nedds mannequin commented Jun 23, 2008

BPO 3182
Files
  • pytree.py: new version of pytree.py
  • 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 2008-08-21.22:27:30.913>
    created_at = <Date 2008-06-23.17:25:43.387>
    labels = ['expert-2to3', 'performance']
    title = '2to3 Slight Patch'
    updated_at = <Date 2008-08-21.22:27:30.912>
    user = 'https://bugs.python.org/nedds'

    bugs.python.org fields:

    activity = <Date 2008-08-21.22:27:30.912>
    actor = 'benjamin.peterson'
    assignee = 'collinwinter'
    closed = True
    closed_date = <Date 2008-08-21.22:27:30.913>
    closer = 'benjamin.peterson'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2008-06-23.17:25:43.387>
    creator = 'nedds'
    dependencies = []
    files = ['10713']
    hgrepos = []
    issue_num = 3182
    keywords = []
    message_count = 5.0
    messages = ['68641', '68692', '68694', '69632', '69633']
    nosy_count = 2.0
    nosy_names = ['collinwinter', 'nedds']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = None
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue3182'
    versions = ['Python 2.6']

    @nedds
    Copy link
    Mannequin Author

    nedds mannequin commented Jun 23, 2008

    This is a small patch to the 2to3 tool, replacing some calls to
    isinstance (x,y) with type(x) is y in the file pytree.py. Although there
    is only a slight performance increase for each time this change is made,
    the recursive nature of pattern matching means that isinstance was being
    calling hundreds of thousands of times per file, so overall these minor
    changes result in a 3-4% speed increase in my limited testing. It
    currently fails only one test due to line 432 in test_pytree, because I
    had to rename the type parameter to new_type so I could call type() on
    something. But with the line in the test file changed, it passes all tests.

    @nedds nedds mannequin assigned collinwinter Jun 23, 2008
    @nedds nedds mannequin added topic-2to3 performance Performance or resource usage labels Jun 23, 2008
    @collinwinter
    Copy link
    Mannequin

    collinwinter mannequin commented Jun 24, 2008

    I'm not wild about making this change for such a minimal improvement
    (which I would guess falls within the margin of error), since it will
    limit extensibility and testability. I think I'd be fine with it if the
    benefit were >10%, but 3% doesn't sound significant enough.

    @nedds
    Copy link
    Mannequin Author

    nedds mannequin commented Jun 24, 2008

    I don't think the improvement falls in margin of error, but maybe I'm
    wrong. The problem was that even when just run on a single file,
    isinstance was being called upwards of 100,000 times. I guess it doesn't
    merit inclusion on its own though, but with other things I'm working on,
    I think it makes sense.

    @collinwinter
    Copy link
    Mannequin

    collinwinter mannequin commented Jul 14, 2008

    So, revisiting this...

    On the face of it, I'm not convinced that the isinstance(x, Leaf) ->
    type(x) is Leaf changes are correct: certain fixers have in the past
    utilized their own subclasses of Node, and I can foresee this being done
    again in the future. Reverting those changes seems to remove the speedup
    you observed.

    @nedds
    Copy link
    Mannequin Author

    nedds mannequin commented Jul 14, 2008

    Fair enough. I guess that even though there's a little bit of a
    performance improvement from this, it does hurt extensibility, so its
    probably not a worthwhile change after all.

    @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
    performance Performance or resource usage topic-2to3
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant