加载可选DLL时的性能问题 [英] Preformance Question when loading optional DLL

查看:57
本文介绍了加载可选DLL时的性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

从性能的角度来看,我应该加载可选的DLL吗?或者这已经发生了,因为我正在使用反射?



当调用我的DLL子程序时,会运行什么线程?



- 以下是我用来加载的代码的一部分DLL MainForm:



Question:
From a performance standpoint, should I load the optional DLL in it's own tread or does this already happen because I'm using reflection ?

When calling my DLL sub , what thread will this be running off ?

- Below is part of the code I'm using to load the DLL MainForm:

GenericInstance = Activator.CreateInstance(KDMDLL.GUI_MainForm)
KDMCustomGUI = CType(GenericInstance, Form)
KDMCustomGUI.Show()





-我在我的DLL中用这样的东西进一步调用Subs





-I'm further calling the Subs in my DLL with something like this

Dim Arguments() As Object = {CType(SubName, Object), Par}
Dim A As Object = Activator.CreateInstance(KDMDLL.GUI_Class)
KDMDLL.GUI_INTERFACE_SUB.Invoke(A, Arguments)





感谢您帮助我: -



Thanks for helping me out :-

推荐答案

请参阅我对该问题的评论。如你所见,我不确定一些细节。但实际上,我会回答:在一个单独的线程中执行它是没有意义的。是的,我非常肯定。



(顺便说一句,线程很少用于提高性能。它们可以有效地提高吞吐量,但这不一样并且不是线程的主要目的。对于热身练习,成像你有一个双码CPU和只有一个任务有限数量的操作,比方说,很多。显然,你可以快速,如果你可以在两个线程中打破它,如果可能的话(有独立的子任务)。但是更多的线程怎么样?难道他们只会减慢获得最终结果的速度。这就是你不打算改变这个任务的任何参数。但是如果你想根据观察到的中间结果手动改变它们会怎么样呢。那么即使你没有加速任何东西,UI线程也会使它变得更有效率,因为你不会浪费时间去做无用的事情。计算的一部分。



线程更多用于逻辑,而不是性能。)



-SA
Please see my comment to the question. As you can see, I'm not sure about some detail. But practically, I would answer: doing it in a separate thread makes no sense. Yes, I'm pretty much sure.

(By the way, threads are rarely used to improve performance. They effectively can improve throughput, but this is not the same, and is not the main purpose of threads. For a warm-up exercise, imaging you have a two-code CPU and only one task with some limited number of operations, let's say, many. Apparently, you can make it fast, if you break it in two thread, if this is possible (there are independent sub-tasks). But how about more threads? Isn't it apparent that they would only slow down obtaining the final result. This is if you are not going to change any parameters of this task. But what if you want to change them manually depending on observation of intermediate results. Then UI thread will make it more efficient, even though you don't accelerate anything, just because you would stop wasting time for useless part of calculations.

Threads are more for logic, less for performance.)

—SA


在DLL中加载时,您将加载到当前的AppDomain中(至少使用您在问题中描述的方法)。当你加载它时,加载发生在调用加载DLL的函数的同一个线程中。



如SA所说,将DLL加载到AppDomain非常快,因为代码在实际运行之前没有编译或JIT。然而,您可能遇到的问题有点不同。所有UI组件都在同一个线程(UI线程)上运行,因此您实际上无法将表单加载到不同的线程中,它始终位于UI线程上。



缓慢的部分是调用,它使用反射。我真的不确定在VB中使用它的最佳方法,但在C#中如果我们在编译时知道方法名称,我们可以使用动态方法,例如:



When loading in a DLL you are loading into the current AppDomain (at least using the methods you describe in your question). When you are loading it, the load happens in the same thread that calls the function that loads the DLL.

As SA said, loading a DLL into an AppDomain is very fast, as the code is not compiled or JIT'd until its actually run. The problem you may have however is a little different. All UI components run on the same thread (the UI thread), so you really can't load your form into a different thread, it'll always be on the UI thread.

The slow part is the "invoke", which uses reflection. I'm really not sure the best way around this in VB, but in C# if we know the method name prior to compile time we can use dynamic methods, like:

dynamic userForm = Activator.CreateInstance("KMDLL.GUI_MainForm");
userForm.SomeProperty = somevalue;
userForm.SomeMethod();





。右侧的运营商。直到运行时才进行评估,因此我们可以调用任何我们想要的东西,而不会让编译器抱怨它不存在。这比使用Invoke更快,调用比调用方法慢100倍。查找更快就是在谷歌上调用以获得更多帮助。



The operator on the right side of the "." isn't evaluated until run time, so we can call anything we want without the compiler complaining that it doesn't exist. This is faster than using Invoke, invoke is up to 100 times slower than just calling the method. Look up faster was to do invoking on google for more help.


它将位于名为CreateInstance的线程上。
It'll be on the thread that called CreateInstance.


这篇关于加载可选DLL时的性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆