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

Speed up EnumKey call #40433

Closed
garth42 mannequin opened this issue Jun 22, 2004 · 9 comments
Closed

Speed up EnumKey call #40433

garth42 mannequin opened this issue Jun 22, 2004 · 9 comments

Comments

@garth42
Copy link
Mannequin

garth42 mannequin commented Jun 22, 2004

BPO 977553
Nosy @loewis, @theller, @birkenfeld
Files
  • _winreg_enumkey_speedup.patch: Patch to spped up _winreg.EnumKey
  • winreg-enumkey.diff: revised patch
  • 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 2006-02-18.23:37:35.000>
    created_at = <Date 2004-06-22.15:22:11.000>
    labels = ['OS-windows']
    title = 'Speed up EnumKey call'
    updated_at = <Date 2006-02-18.23:37:35.000>
    user = 'https://bugs.python.org/garth42'

    bugs.python.org fields:

    activity = <Date 2006-02-18.23:37:35.000>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Windows']
    creation = <Date 2004-06-22.15:22:11.000>
    creator = 'garth42'
    dependencies = []
    files = ['6045', '6046']
    hgrepos = []
    issue_num = 977553
    keywords = ['patch']
    message_count = 9.0
    messages = ['46206', '46207', '46208', '46209', '46210', '46211', '46212', '46213', '46214']
    nosy_count = 6.0
    nosy_names = ['loewis', 'theller', 'georg.brandl', 'garth42', 'alanmcintyre', 'mmangino']
    pr_nums = []
    priority = 'high'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue977553'
    versions = ['Python 2.4']

    @garth42
    Copy link
    Mannequin Author

    garth42 mannequin commented Jun 22, 2004

    This patch removes the RegQueryInfoKey call and
    replaces it with a call to EnumKeyEx. This greatly
    speeds up this call.

    The script below times

    python 2.3 5531 89.7130000591
    python 2.4 +patch 5531 0.0469999313354

    start = time.time()
    i = 0
    try:
      while 1:
        _winreg.EnumKey(_winreg.HKEY_CLASSES_ROOT, i)
        i += 1
    except WindowsError:
      pass
    print i, time.time() - start

    @garth42 garth42 mannequin closed this as completed Jun 22, 2004
    @garth42 garth42 mannequin added the OS-windows label Jun 22, 2004
    @garth42 garth42 mannequin closed this as completed Jun 22, 2004
    @garth42 garth42 mannequin added the OS-windows label Jun 22, 2004
    @mmangino
    Copy link
    Mannequin

    mmangino mannequin commented Jul 14, 2004

    Logged In: YES
    user_id=74879

    This looks good to me, but I think the buffer size is off by
    one. I read the SDK to say tha they key can be 255
    characters. That means you need to allocate 256 characters
    to allow for the null terminator. Could you create a test
    case for a max length registry key?

    @theller
    Copy link

    theller commented Jul 14, 2004

    Logged In: YES
    user_id=11105

    I'm curious: Why did you replace RegEnumKey with
    RegEnumKeyEx? Are there any advantages of the latter?

    @garth42
    Copy link
    Mannequin Author

    garth42 mannequin commented Jul 14, 2004

    Logged In: YES
    user_id=45280

    mmangino:

    Yes you're correct it should be 256 in both cases. Doh! I'll
    attach a new patch in a while. but It's easy to mmodify the
    patch and up the linit to 256

    theller:

    The advantage of the latter is it returns the Length of the
    string returned so we can pass it straight back to the
    string creation funtion in python without a strlen.

    also the SDK says this....

    Note This function is provided only for compatibility with
    16-bit versions of Windows. Applications should use the
    RegEnumKeyEx function.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jul 26, 2004

    Logged In: YES
    user_id=21627

    Also, please follow the Python style guide for C code, PEP-7. In particular:

    • use tabs for indentation, with a tab being worth 8 spaces
    • omit spaces after opening and before closing parens
    • put the opening brace of a code block on the same line as
      the keyword

    @alanmcintyre
    Copy link
    Mannequin

    alanmcintyre mannequin commented Feb 27, 2005

    Logged In: YES
    user_id=1115903

    I think it's a good idea to get 16-bit Windows functions out
    of Python per Microsoft's recommendation, especially when
    doing so can also help performance.

    It looks like this patch still needs some cleanup and a test
    or two. If nobody else wants to do it I can probably finish
    it up.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Mar 3, 2005

    Logged In: YES
    user_id=21627

    garth42, can you please indicate whether you are willing to
    work on the patch, and if so in what time frame?

    @birkenfeld
    Copy link
    Member

    Logged In: YES
    user_id=1188172

    Attached a revised patch following coding style and adding
    additional error handling.

    winreg-enumkey.diff

    @birkenfeld
    Copy link
    Member

    Logged In: YES
    user_id=1188172

    Cleaned up and committed in rev. 42475.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants