Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dnlib vs cecil memory usage camparing

See original GitHub issue

I tried with PaintDotNet assemblies, What is your opinion?

dnlib usage memory 133MB

            var moduleContext = new ModuleContext();
			var asmResolver = new AssemblyResolver(moduleContext, true);
            var resolver = new Resolver(asmResolver);
			moduleContext.AssemblyResolver = asmResolver;
			moduleContext.Resolver = resolver;
		    ModuleDefMD moduleDefMd = ModuleDefMD.Load(@"D:\PaintDotNet.exe", moduleContext);


cecil usage memory 40MB

		    ReaderParameters readerParameters = new ReaderParameters
		        AssemblyResolver = new CustomResolver()
		    ModuleDefinition moduleDef = ModuleDefinition.ReadModule(@"D:\PaintDotNet.exe", readerParameters);


Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

0xd4dcommented, Jun 12, 2018

Looks like it’s the mmapped IO. With it disabled (use File.ReadAllBytes()) and reading PDB files is disabled, process explorer says WS is 69MB (dnlib) vs 52MB (cecil). WIth mmapped IO enabled, dnlib’s WS is 112MB. The example is similar to yours except I made it more real-world by iterating over all types and members and reading method bodies.

The most important part of dnlib is that it can read obfuscated assemblies. That’s the reason I wrote it. If it uses more memory and more CPU, then that’s OK with me because it must be able to read real world assemblies, not only assemblies following the ECMA spec. Memory is very cheap.

bprgcommented, Jun 12, 2018

I attached example cecil and dnlib,

dnlib opens PDB files by default (that will use more memory), does cecil? Maybe that’s the reason, How to disable PDB reader?

Did dnlib almost cause an OS crash when it allocated those 133MB? Does not crash after save I’ve comparing memory task manager. Please download Paint.Net

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the difference between AsmResolver and dnlib? #111
It allows for preserving metadata tokens, and allocating and assigning new metadata tokens to new members before saving a module to the disk....
Read more >
Cecil can't handle obfuscated assemblies, doesn't fully support mixed mode assemblies, doesn't read .NET assemblies the same way the CLR does and many...
Read more >
Accessing Assembly Metadata with Reflection or Mono ...
it uses a lot more memory than Reflection – roughly twice as much on average (it varies from 50% more to twice as...
Read more >
c# - How can I programatically (using reflection?) change a ...
I believe that changing the method body will be less error prone than trying to use Assembly/Module/TypeBuilder and Reflection.Emit to try and ......
Read more >
Challenge 8: backdoor
The challenge uses the concept of Dynamic Methods in .NET to conceal meaningful code from static analysis and debugging tools like dnSpy.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found