TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Decompiling C# (async/await)

57 pointsby invabout 12 years ago
A look under the hood of a C# decompiler.

5 comments

CodeCubeabout 12 years ago
About the only time that you have to be really careful with stuff like this is if you're writing something that's super sensitive to GC pauses, such as an XNA game. In those cases, yield return, linq, lambdas, some foreach loops will all generate short lived objects that will cause the GC to kick in more often. So if you're doing that in every update loop you could end up with performance issues. And even that is only on some platforms, as the desktop GC does a great job of dealing with short term garbage.<p>But in most cases such as ASP.NET MVC actions, or doing an API call in a desktop app, the maintenance and high level code simplification you can get by using these techniques <i></i>far<i></i> outweighs the low level "cost" of the code generated by the compilers.<p>It's good to know what's going on under the covers though.
评论 #5344598 未加载
评论 #5344409 未加载
kevingaddabout 12 years ago
The ILSpy team's hard work is part of what made it possible for me to write my .NET -&#62; JS compiler (<a href="http://jsil.org/" rel="nofollow">http://jsil.org/</a>). My ~120k LoC wouldn't work without their ~450k LoC (well, I don't consume all 450k...)<p>ILSpy is a pretty interesting application/library to look at under the hood. The decompilation logic that transforms .NET bytecode (MSIL) into higher-level data structures is split into a bunch of well-defined transform phases that run in a pipeline, which means you can actually step through the pipeline and watch it improve the readability and semantic clarity of the IL one step at a time. It's an incredibly valuable debugging tool and really useful for understanding how this kind of decompiler works, and it was a big influence on how I ended up designing the similar parts of my compiler.<p>As a whole, I think ILSpy demonstrates just how valuable it is to have a really well specified instruction set sitting beneath your compiler and runtime. MSDN's documentation for the instruction set is clear and understandable and libraries like Cecil and ILSpy make it easy to load, manipulate, and save for whatever your purposes might be - runtime code generation, machine transforms of compiled code, obfuscation, deobfuscation, or outright cross-compilation.
评论 #5344610 未加载
guiomieabout 12 years ago
Its great to see a post on c# around here these days.
SideburnsOfDoomabout 12 years ago
Inside every language there is a minimal language with all the syntactic sugar translated into a subset of the language.<p>e.g. the C# compiler turns "var a = 3;" into "int a = 3;" It turns anonymous lambdas into methods with generated names (i.e turns one line of code into 3-4 lines), and makes classes with constructors that do the environment capture if needed. It turns "yield return" generator methods into objects that have state.<p>While async/await is a cool feature and is worth using, it is worth noting the up trend in complexity of generated code – and ansyc/await generates significantly more code in the simpler language without this feature than previous new features did.<p>How much code does an await statement give rise to? it looks like about 40-50 lines to me.
评论 #5342945 未加载
评论 #5343000 未加载
评论 #5343293 未加载
评论 #5342935 未加载
TomJoadabout 12 years ago
ILSpy is probably one of the best utility programs I have ever used... It has saved me countless times from poorly documented API's and helps me work around countless bugs in third party libraries.