Add caching to guarded_import to boost performance#163
Add caching to guarded_import to boost performance#163jan-jockusch wants to merge 2 commits intomasterfrom
Conversation
Using "import" in Python Scripts triggers the execution of guarded_import each time. This performs a security test and then the import itself. The import is fast because the Python interpreter caches this. The security test is costly, and always yields the same result. This patch inserts a cache to skip this test on repeated executions, speeding up the Python Scripts.
|
I cannot push to my branch. Therefore, the changelog is still missing. |
|
Please try the push again, I just deleted a broken branch protection rule that wantd to cover all possible branches, which makes no sense. |
Yes! Push has worked. Thank you! |
There was a problem hiding this comment.
This seems a good idea, but for correctness I believe this cache should be invalidated when allow_module is called.
|
I'll look into adding clearing the cache on For motivation: This shaves off 4% of time spent in our scenario, with many scripts in Data.fs utilizing |
Using "import" in Python Scripts triggers the execution of guarded_import each time. This performs a security test and then the import itself. The import is fast because the Python interpreter caches this. The security test is costly, and always yields the same result. This patch inserts a cache to skip this test on repeated executions, speeding up the Python Scripts.
If your pull request closes an open issue, include the exact text below, immediately followed by the issue number. When your pull request gets merged, then that issue will close automatically.
Closes #