Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Compiler Optimizations

Compiler Optimizations

Scheduled Pinned Locked Moved C#
csharpdotnetquestiontutorialdiscussion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrew Shapira
    wrote on last edited by
    #1

    Where is a discussion of the current and future optimizations that the C# compilers do? When I see things like the following I start to question my faith in csc being good at optimizing. (The same kind of thing shows up in cordbg when looking at the JIT code for a similar example.) % cat y.cs using System; class A { bool On { get { return true; } } public void Print() { if (On) { Console.WriteLine("On"); } } } class ConditionalTest { static void Main() { A a = new A(); a.Print(); } } % csc /optimize+ y.cs Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4 for Microsoft (R) .NET Framework version 1.1.4322 Copyright (C) Microsoft Corporation 2001-2002. All rights reserved. % ildasm y.exe .method public hidebysig instance void Print() cil managed { // Code size 19 (0x13) .maxstack 2 IL_0000: ldarg.0 IL_0001: call instance bool A::get_On() IL_0006: brfalse.s IL_0012 IL_0008: ldstr "On" IL_000d: call void [mscorlib]System.Console::WriteLine(string) IL_0012: ret } // end of method A::Print % At least the compiler eliminates the "if" test when "On" is replaced with "true" in the test.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups