Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] Speed up Registry initialization (#1844)
* Speed up Registry initialization This PR addresses #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 * Add comment with PR tag Explain why we avoid `inspect.stack()` with link to PR
- Loading branch information