Repository navigation
[Optimization] Avoid runtime Guid parsing for new Guid("0A3976C5-4529-4ef8-B0B0-42EED37082CD") #1387
Description
Activity
- addedTenet-PerformanceRegression in measured performance of the product from goals.Regression in measured performance of the product from goals.
on Mar 19, 2015 We generally hesitate to make the compiler understand the semantics of particular APIs.
Compiler already understands format of Guids, because it generates Guid ctor calls for COM interface instantiations, and also parses and validates [Guid(...)] attributes.
I dislike special casing, especially for performance improvements that are only theoretical.
Does Roslyn not support syntaxrewriters anymore? I remember reading links such as
http://stackoverflow.com/questions/28515505/accessing-symbolinfo-from-modified-syntaxnode-in-roslyn-syntaxrewriter
or
https://joshvarty.wordpress.com/2014/08/15/learn-roslyn-now-part-5-csharpsyntaxrewriter/
or
http://www.mindscapehq.com/blog/index.php/2011/10/20/in-bed-with-roslyn/that make it seem to me as if you could hook into the compilation step, perform transformations and then give those back to the pipeline. Or is this stuff all just for quickfixes (ie for changing source code vs. leaving source untouched)? I may be misunderstand this (I admit I never really played with any samples).
If that is possible, would the proposed transformation not be a prime (and relatively) example that could be delivered by the community (or microsoft) but without having the compiler itself know about this special case?
I have a feeling that there may be lots of opportunities for these, individually, small optimization in a lot of places if someone wrote code that better understands APIs (moving things from runtime to compile time computation, but also simply transforming readable, general code to more specialized, more performant code in specialized cases, ie transforming a foreach array.Where into a for loop with an if). Things like that.
Visual Studio today does not have a mechanism to splice user code into the compilation pipeline for C# or VB.
Going to close out as this would fall under hte umbrella of 'interceptors'. This way generalized optimizations can be provided externally, and the compiler doesn't need to special case knowledge of various .net apis.
- added a commit that references this issue
on Aug 18, 2026
Currently expressions like
new Guid("0A3976C5-4529-4ef8-B0B0-42EED37082CD")are compiled naively, and this results in an invocation of an expensive parsing method at runtime. We could do the parsing at compile-time and invoke a constructor that accepts integer arguments.Note that expressions of this form are generated by the compiler as part of COM interface instantiations like
new Word.Application().