-
-
Notifications
You must be signed in to change notification settings - Fork 511
Use global WScript object instead of creating it every time it's used #1976
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
Comments
Awesome, thanks! A few coments:
It is automatically signed when released
The UDF tests are under
The version here needs to match the version of the dll. I've also added a few comments on how to edit the add-in: https://github.com/xlwings/xlwings/blob/main/DEVELOPER_GUIDE.md#addin => I think the real issue here is that it runs |
I agree. In my add-ins I have something similar, where the configuration is spread across one I usually have one When the object is instantiated, it immediately reads all the values from the Config sheet into a dictionary. Reading them lazily would be a waste of time, because it would need to search each one the first time it's required, while loading them all requires only one scan. Some settings are loaded lazily, for example the ones coming from http rest apis, because it would be too slow to read them all, and one never needs all of them, and sometimes the full list is not even known. The class has methods like:
|
I wanted to create a pull request, but:
xlwings32-dev.dll
)So I did the change on the add-in installed by
pip
and I'm describing the changes and the reason why I did it here.Executing
CreateObject("Wscript.Shell")
once and keeping a global object makes the execution of UDFs more than 3 times faster. On my computer with default configuration it goes from 0.013 down to 0.0038 seconds per call.I have defined this UDF:
I have added
NCalls = NCalls + 1
before eachCreateObject("Wscript.Shell")
and ran this test:The test shows that
CreateObject("Wscript.Shell")
is executed 16 times per UDF execution (with the default configuration I am using) and that the time required for calling 100 UDFs is 1.32 seconds:After removing the calls to
CreateObject("Wscript.Shell")
and using a static object and running this test:The test shows that the time required for calling 100 UDFs is 0.38 seconds:
Here is the diff (after manually removing parts that were different between the installed add-in and the one in the repository). I copied the
WScript()
function from one of my old add-ins, I've been using it for years:The text was updated successfully, but these errors were encountered: