Skip to content

[Optimization] Avoid runtime Guid parsing for new Guid("0A3976C5-4529-4ef8-B0B0-42EED37082CD") #1387

Description

@VladimirReshetnikov

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().

Activity

  1. added
    Tenet-PerformanceRegression in measured performance of the product from goals.
    on Mar 19, 2015
  2. gafter commented on Mar 19, 2015

    @gafter
    Member

    We generally hesitate to make the compiler understand the semantics of particular APIs.

  3. VladimirReshetnikov commented on Mar 19, 2015

    @VladimirReshetnikov
    Author

    Compiler already understands format of Guids, because it generates Guid ctor calls for COM interface instantiations, and also parses and validates [Guid(...)] attributes.

  4. agocke commented on Mar 19, 2015

    @agocke
    Member

    I dislike special casing, especially for performance improvements that are only theoretical.

  5. added this to the milestone on Mar 20, 2015
  6. chrisaut commented on Mar 20, 2015

    @chrisaut

    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.

  7. gafter commented on Mar 20, 2015

    @gafter
    Member

    Visual Studio today does not have a mechanism to splice user code into the compilation pipeline for C# or VB.

  8. self-assigned this
    on Apr 8, 2015
  9. removed their assignment
    on May 12, 2015
  10. removed this from the milestone on Nov 23, 2015
  11. added this to the milestone on Dec 3, 2015
  12. CyrusNajmabadi commented on Nov 10, 2025

    @CyrusNajmabadi
    Contributor

    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.

  13. added a commit that references this issue on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions