您的位置:首页 > 其它

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

2008-01-15 21:40 357 查看
方法:
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: