Kbase 17470: How To Improve ActiveX or OLE Automation performance
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/16/2008 |
|
Status: Unverified
GOAL:
How to improve ActiveX Automation performance
GOAL:
How to Improve OLE Automation performance
FIX:
If performance problems are encountered when executing 4GL code against Automation Objects there are a couple of things to try.
1. If you are using Automation with Microsoft Word or Excel you could record the steps of the process in a Word or Excel Macro. You can then call the Macro with the Automation object and allow the Automation Server (Excel or Word) to handle the rest of the operation.
2. Try eliminating all unnecessary object references. For example, the following sample code refers to an ActiveX Automation Object called "TestObject".
DEFINE VARIABLE comTestObject AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE intCount AS INTEGER NO-UNDO.
CREATE "TestObject.Application" comTestObject.
DO intCount = 1 TO comTestObject:someIntegerReference:
comTestObject:subObject:prop1 = intCount.
comTestObject:subObject:prop2 = intCount + 1000.
comTestObject:subObject:prop3 = intCount + 10000.
comTestObject:subObject:doit().
END.
RELEASE OBJECT comTestObject.
The above automaton code will work, but every line inside of the DO/END block is using two (2) COM object references each. Each reference made to a COM object adds execution overhead since we do everything dynamically (Late Binding).
Rewriting the above code as follows eliminates half of the object references. The above loop makes 8000 object references as oppose to the below code which accomplishes the same tasks but only makes 4000 object references.
DEFINE VARIABLE comTestObject AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE comSubObject AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE intCount AS INTEGER NO-UNDO.
CREATE "TestObject.Application" comTestObject.
comSubOject = comTestObject:SubObject.
DO intCount = 1 TO comTestObject:someIntegerReference:
comSubOject:prop1 = intCount.
comSubOject:prop2 = intCount + 1000.
comSubOject:prop3 = intCount + 10000.
comSubOject:doit().
END.
RELEASE OBJECT comTestObject.
RELEASE OBJECT comSubOject.