comtypes
comtypes copied to clipboard
Can we remove the comments generated by `CodeGenerator.ComInterfaceBody`?
I noticed during the bug fix for #524 that the wrapper module for mshtml.tlb have a considerably large file size.
Given the large number of definitions in the COM type library, it’s inevitable that the file size of the mshtml.tlb wrapper module becomes large.
However, in the current comtypes implementation, CodeGenerator.ComInterfaceBody generates comments proportional to the number of COM interfaces and methods.
https://github.com/enthought/comtypes/blob/c8f3e2e0fe628643476b61d7e0bc5b2103fd6231/comtypes/tools/codegenerator.py#L1185-L1253
I attempted to reduce the file size by removing these comments.
Actual behaviors
Using Python 3.10.10, I compared the output values obtained by running the following script with the codebase at commit c8f3e2e as is, and with the codebase where the part that generates comments in CodeGenerator.ComInterfaceBody has been removed.
import time
import os
from comtypes import client
def main():
start = time.perf_counter()
mod = client.GetModule("mshtml.tlb")
end = time.perf_counter()
print(f"{end-start:.2f}", os.path.getsize(mod.__wrapper_module__.__file__))
if __name__ == "__main__":
main()
Execution results
with generating comments by CodeGenerator.ComInterfaceBody
30.91 13365249
without generating comments by CodeGenerator.ComInterfaceBody
30.78 12693666
There is a difference of about 0.64MB in file size. There is also a difference of more than 0.1 seconds in the time it takes to generate the module.
With the type annotation feature introduced from comtypes==1.3.1, if we simply want to know the interface, we can now refer to static type hints.
So, these comments might have served their purpose.
However, these comments have been around for a long time, so caution is needed when removing them.
I am soliciting opinions from the community on whether it is better to reduce the file size and the time it takes to generate by removing these comments, or whether we should keep them for backward compatibility.
Any opinion would be appreciated.