This project has moved. For the latest updates, please go here.

Please speed up the COMObject create process!!

Jun 14, 2014 at 7: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.Ldarg_0);
            il.Emit(OpCodes.Ldarg_1);
            il.Emit(OpCodes.Ldarg_2);
            il.Emit(OpCodes.Ldarg_3);
            il.Emit(OpCodes.Newobj, ctor);
            il.Emit(OpCodes.Ret);
            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 8: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 8:32 AM
Edited Jun 14, 2014 at 9:40 AM
Fasterflect - .NET Reflection Made Fast and Simple
https://fasterflect.codeplex.com
Fast Invoker
https://fastinvoker.codeplex.com

We can learn from Fasterflect to speed up the method call

I FOUND THE SPEED AT SAME LEVEL :(
Coordinator
Jun 20, 2014 at 3: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)

*Sebastian