Loading user information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading user information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements


Blue Ink Blue Ink
  • Has anyone considered writing an MSIL interpreter in C#?

    @BitFlipper: I didn't claim it was difficult to solve, just that it was expensive. As you correctly deduced you need to keep track of the type of every value that gets pushed onto the stack, either using a separate stack or by "decorating" each stack slot (memory alignment might make this quite wasteful). Either way you are consuming more precious RAM and more CPU cycles. Might not seem much, but once you consider the sheer number of stack operations involved you see how this piles up.

    A second interesting point is that MSIL essentially describes a pure stack machine (as in "without registers"). That was a good choice as it allows high level compilers to generate code that is CPU agnostic and because it yields compact code. The obvious disadvantage of stack machines is that they require roughly twice as many operations to execute as compared to the equivalent register machine. On the desktop this is ok as the JIT is CPU-specific and knows how to handle registers, but an interpreter will be stuck with the inefficiency.

    Just to give you a sense of what I mean: as you probably know, in order to execute a simple "ADD" instruction you need to:

    pop the first operand from the stack and store it into a register
    pop the second operand from the stack and store it into another register
    perform the addition
    push the result onto the stack

    Seems harmless, but once you consider that executing the next operation will most likely start with "pop the first operand into a register", it screams bloody murder. Unfortunately, an interpreter cannot predict what the next operation will do so it will have to go through the dance pushing and popping values uselessly.

    There are several other concerns (field access, reevaluation of the "this" pointer, parameter passing etc.) and optimizations that cannot be performed on a stack machine, but I'll leave them for another time.

    These are shortcomings of the whole idea of interpreting MSIL, not flaws in the implementation of the MF interpreter which I'm assuming to be quite good (MS has far more brilliant developers than it's generally credited for). So, if you are in for big performance improvements, I think it would be more productive to try and change the whole game, not trying to shave off cycles from the interpreter. The only issue I can foresee is that you may end up trading code size for RAM and performance; while this is generally ok as RAM and CPU muscle are scarcer than Flash space, it might be an interesting challenge to fit all the libraries on your device. You may have to go for a hybrid solution.

    At any rate, even considering all the inefficiencies I listed, I still cannot figure out how you might get the 1:1000 figure you mention. What are you comparing the performance to, exactly?

  • Has anyone considered writing an MSIL interpreter in C#?

    @BitFlipper: I suspect one of the sources of the poor performance you are witnessing is that are not just comparing native code vs interpreted IL, you are also missing out on all the optimizations the JIT is in charge of.

    Another issue is that MSIL is not very interpreter friendly. For instance, while the java bytecode contains different opcodes depending on the type of its operand (e.g. dadd, fadd, iadd), MSIL does not as it relies on the fact that the JIT can always determine statically the stack state at any given point and emit the correct sequence of machine instructions.

    Unfortunately, a pure interpreter cannot do that, which means it must keep track of the stack contents somehow and that's expensive both in terms of memory and CPU cycles.

    So, maybe you can shave a few cycles here and there in the interpreter, but I suspect you won't get significant performance gains that way; at least not the kind of improvements you couldn't get by upgrading your hardware.

    I would probably try either to translate MSIL to a different bytecode (trading code size for performance) or, better, to compile chunks of code to native. This doesn't necessarily rule out cooperative multithreading: you could always inject code that keeps track of some sort of timeslice and traps to the VM when it runs out.

  • Internation​al phone number formatting

    @W3bbo: you may want to try libphonenumber. The online JS demo handled perfectly all the numbers I threw at it, from several countries.

    As an added bonus, it distinguishes between mobile and landline where the numbering plan permits it.

  • Windows 8 Metro Look. Why? Why? Why?

    , cbae wrote


    I think the jury is still out on the tablet in its current form.


    If you are referring to Windows tablets, I concur. But from what I've seen, the iPad proved that users like the form factor, even when it implies using an OS and applications they are unfamiliar with. Might have been overhyped and all, but it's taken hold in places I would have never imagined it to, despite a relatively high price tag.

  • Windows 8 Metro Look. Why? Why? Why?

    @OmegaZeroKiller: I balked when you mentioned "real computers"... it reminded me of one of my favorite quotes from a book called "the zen of programming" (1988):

    A novice went into the master's cubicle and saw a new computer sitting upon the master's desk. "What is that computer?" asked the novice.
    The master placed his hand upon a small box that was connected to the computer by a wire.  "Behold," said the master, "This device controls what we see on the screen.  The screen simulates a desk.  For example, here is a filing cabinet and a trash depository.  Here also is a typewriter and a calculator."
    "This is a wonderful invention," whispered the novice in awe.
    "It is not as wonderful as it seems," said the master. "Can you see the two desks?"
    The novice nodded.  "One is on the floor, the other is on the screen," he remarked.
    "Just so.  Now, is there something missing on one of the two desks?"
    The novice pondered for a moment.  "One of the desks does not have a computer on it," he said.
    The master shook his head.  "Neither of the desks has a computer on it."

    And even back then, there were still people scoffing at the whole "personal computer" thing, maintaining that nothing short of a full-fledged mainframe could be called a "real computer".

    Things evolve, and sales figures tell us that tablets are here to stay. It is only natural that Windows and all the applications you love and use will eventually adapt to become touch-friendly, just as they became mouse friendly in the eighties.

  • Questions about the HTC Trophy

    @Doctor Who: as far as I understand, the Motion combined sensor works best when the phone has an accelerometer, compass and gyroscope available. It still works, although not with the same quality, when the gyroscope is absent.

  • Implementing 'Sheets' in Windows

    In WPF you could probably get something like that with a Popup. If I remember correctly that's how they implemented several flyouts in the WPF Ribbon. The bending part would still require the Pixel Shader _aL mentioned, but that's actually fun.

  • "None of us at Microsoft can say anything until //build/ in September."

    Considering the knee-jerk reaction they got with partial demos and statements, it doesn't surprise me much. They are seriously risking a marketing issue of Vista proportions here, so it makes sense to try and get the whole story out, all in one piece.

  • Denmark bans Marmite

    @Dr Herbie: btiyf (Bing Translator is your friend).

    If I read correctly, it says that they didn't ban Marmite: it's just that food enhanced with vitamines must be specifically approved before it can be sold and no submission for Marmite or Vegemite was received yet.

    Hmm.. in the translation the two products become "Marmite and Vegemite lubrication". I see how they might object if one tried to dress his salad with WD-40. Tongue Out

  • Skype Future Speculation

    @W3bbo: A Silverlight client would make a lot of sense, not just for the Linux implication, but because of WP7 and the upcoming ARM tablets (if and when).

    This might have a nice side effect: Microsoft will have either to provide its own SL implementation for Linux, or to help Miguel on Moonlight, to make sure it's on par with SL. Either way, that would be a good thing.