This project has moved and is read-only. For the latest updates, please go here.

Please speed up the COMObject create process!!

Jun 14, 2014 at 8:28 AM
NetOffice cached the class type, I thank it can also cache the constructor.
_wrapperTypeCache.Add(fullClassName, classType);
                COMObject newClass = Activator.CreateInstance(classType, new object[] { caller, comProxy, comProxyType }) as COMObject;
                return newClass;
private static Type[] Params = new Type[] { typeof(string), typeof(string), typeof(string), typeof(XmlDocument) };
    internal void Register(Type type,  ElementNameAttribute att) {
        SpeedQName name = new SpeedQName(att.LocalName, att.NamespaceURI);
        var ctor = type.GetConstructor(Params);
        if (ctor != null) {
            DynamicMethod method = new DynamicMethod(string.Empty, type, Params);
            ILGenerator il = method.GetILGenerator();
            il.Emit(OpCodes.Newobj, ctor);
            Func<string, string, string, XbrlDocument, XbrlElement> fun = method.CreateDelegate(typeof(Func<string, string, string, XmlDocument, XmlElement>)) as Func<string, string, string, XmlDocument, XmlElement>;
            _qname2ImplType[name] = fun;

Jun 14, 2014 at 9:08 AM
I think It's most fast method to Create New Object. Activator.CreateInstance do more work at runtime.
In the Factory _globalObjectList can be ignore If user don't want it by Setting, OR it should only save (cache) the root COMObject, the child COMObject is disposed by the parent object
Jun 14, 2014 at 9:32 AM
Edited Jun 14, 2014 at 10:40 AM
Fasterflect - .NET Reflection Made Fast and Simple
Fast Invoker

We can learn from Fasterflect to speed up the method call

Jun 20, 2014 at 4:03 AM
NO 1.7 use an option to disable the com proxy management by the way. (NetOffice.Settings)
Anyway, in fact you can't improve the method call performance in this way.(this works in .NET but not in COM. )
May its possible to improve performance in CreateProcess, (just for the second call, but most of the time you do this only at once)