Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️ Speed up method
OpCtx.get_or_create
by 10%
Here are some improvements to make the program faster. Note that these optimizations focus on faster access and cleaner initialization. Specifically, I replaced the use of `defaultdict` initialization, optimized the `get` method by reducing the depth of `try-except`, and avoided repetitive imports. ### Changes made. 1. **Initialization of `data`**: Changed from a `defaultdict` of dictionaries to a simple dictionary. This avoids the performance overhead of `defaultdict` and makes initialization fast. 2. **Accessing `data` in `get` method**: Reduced the depth of check by directly checking if `run_data` exists and only then checking the nested dictionary. This reduces the overhead of multiple dictionary accesses. 3. **`get_or_create` method**: Optimized by directly checking membership in `_CTX_REGISTRY` and returning or creating the instance accordingly. These changes should enhance the speed of dictionary operations and the overall runtime efficiency of the program.
- Loading branch information