当前位置: 代码迷 >> 综合 >> cab之性能优化——使用ObGen和CabGen
  详细解决方案

cab之性能优化——使用ObGen和CabGen

热度:36   发布时间:2024-01-18 06:47:00.0

方法:
You just run both tools on your shell and module assemblies, by passing the assembly file path to the tool as the first command line argument. That will generate "assembly.cabgen.dll" and "assembly.obgen.dll". You just need to deploy these alongside your exe/dlls and you should inmediately see the performance improvement.

原理:
By default, the tools will leave a .cs file alongside the generated assembly that contains the source emitted for it. You can inspect that to see how everything works.
Basically the ObGen tool generates a class implementing IPolicyProvider, which is probed by name. If it exists, it is used to retrieve the policies that apply to the object being built, instead of reflecting on the attributes of the type at run-time. Saving reflection is only one part, though. The other is that by avoiding reflection, we can also pass policies that implement strong-typed policy behavior, such as a custom creation policy that will do new MyObject() instead of Activator.CreateInstance.

The combined reflection + strong-typing proved to be a huge perf. boost on the device.

 

  相关解决方案