提供商模型和绩效
使用提供者模式对性能有影响吗?
它是否依赖于每个实例化的反射或其他什么?
Are there any performance implications with using the provider pattern?
Does it rely on reflection for each instantiation or anything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,提供程序模型通常涉及少量反射,因此会对性能产生一点影响,但是,这仅在提供程序对象的实例化中。 一旦对象被实例化,就可以正常访问它(通常通过接口)。 与硬编码模型相比,性能应该差别很小,但从编程角度获得的收益远远超过任何性能损失。 假设提供商实际上可能有一天会发生变化。 如果没有,只需对其进行硬编码。
Yes, the provider model usually involves a small amount of reflection, and therefore, there is going to be a little bit of a performance hit, however, it is only in the instantiation of the provider object. Once the object is instantiated, it is accessed as normal (usually via an interface). The performance versus a hard-coded model should have very little difference, but the gain you get from the programming perspective far outweighs any performance penalty. Assuming the provider actually may change one day. If not, just hard-code it.
每个应用程序域都会实例化一次提供程序。 尽管通过反射更新对象比内联更新对象要慢,但它仍然非常非常快。 我想说大多数商业应用程序不存在性能问题。
Providers are instanced once per app-domain. Although newing up an object via reflection is slower than doing it inline, it is still very, very fast. I would say there is no performance concern for most business apps.