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

[Enhancement] Speed up Registry initialization #1844

Merged
merged 2 commits into from
Apr 14, 2022

Commits on Mar 28, 2022

  1. Speed up Registry initialization

    This PR addresses open-mmlab#1843.
    
    Instead of calling inspect.stack() to read the entire stack and its
    associated source files from disk, walk up the stack to get only the
    specific frame that we need (see [1] for additional information).
    
    This makes imports in downstream projects ~2.5x faster in my local dev
    environment. For mmaction2, for example:
    
    Before:
    
        $ python -m timeit -n1 -r1 "from mmaction.apis import init_recognizer, inference_recognizer"
        1 loop, best of 1: 1.94 sec per loop
    
    After:
    
        $ python -m timeit -n1 -r1 "from mmaction.apis import init_recognizer, inference_recognizer"
        1 loop, best of 1: 754 msec per loop
    
    [1] https://stackoverflow.com/a/42636264/895769
    astahlman committed Mar 28, 2022
    Configuration menu
    Copy the full SHA
    7541aff View commit details
    Browse the repository at this point in the history

Commits on Mar 29, 2022

  1. Add comment with PR tag

    Explain why we avoid `inspect.stack()` with link to PR
    astahlman committed Mar 29, 2022
    Configuration menu
    Copy the full SHA
    be26a30 View commit details
    Browse the repository at this point in the history