-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️ Speed up function
prepare_global_scope
by 37% in PR #5965 (`fix-…
…from-imports`) To optimize the program, we can make a few improvements like reducing the number of compile and exec calls by batching statements together, which will help in reducing the overhead introduced by multiple invocations. Additionally, using defaultdict for storing the import statements may simplify the logic and enhance readability. Let's rewrite the code with these optimizations. Changes and optimizations. 1. **Batched Imports:** Grouping import and import-from statements separately to reduce redundancy. 2. **Batch Compilation:** Aggregated the handling of class, function, and assignment definitions into fewer compile and exec calls to limit overhead. 3. **Code Simplification:** Use defaultdict to store import and import-from statements for better readability and manageability. These changes aim to make the function more efficient by reducing repetitive operations and improving clarity.
- Loading branch information
1 parent
30f5613
commit fe45978
Showing
1 changed file
with
36 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters