Superman returns


“Superman returns”

I whispered this in hushed tones to Aarthi, who was sitting next to me. My heart was pounding, my head was soaring with John Williams’ score and I had goosebumps all over. We had just witnessed Superman herald his return by saving a space shuttle from destruction in the way only Superman can.

Superman returns.

Wow.

As you can tell by now, I spent most of today in the local IMAX theatre. I was watching the first-day, first-showing of ‘Superman Returns’ along with the entire Developer Tools team from Microsoft here. I guess Microsoft pulled a few strings to get its employees first-day tickets to the most anticipated movie of the year :-)

For me, it was an almost religious experience. I’m a huge Superman fan, my obsession with the Man of Steel borders on fanaticism at times. Most of it is due to my childhood – I grew up adoring Superman. I watched all the movies. I had the action figures. I ran around the house with a red cape and a ‘S’ on my chest. I learnt to draw by mimicking the comics I loved so much.

Being such a fan of the Superman movies, the last 10 years was hard. I watched as effort after effort to revive the Superman franchise failed. I was distraught when Christopher Reeve passed away.

All that changed today. In fact, anyone who has been unfortunate enough to be stuck with me for the last week or so got an earful on Superman. And it all culminated for me today. When the familiar theme started playing over the speakers and the X-Ray blue title sequence started to roll, I was in heaven. I was 10 years old again :-)

I’m not going to spoil the movie for you. Don’t walk – run to the nearest theater if you haven’t seen this yet. Or better yet – fly. In fact, that’s what I’m going to do tomorrow – I’m watching the movie again.

Random thoughts

References to the earlier movies

The movie had tons of references to the older movies. I listed out the ones I spotted here. After I wrote this up, I saw a bigger list at Wikipedia(http://en.wikipedia.org/wiki/Superman_Returns#Trivia) .

Superman is much more than just a superhero. Much more than a caped comic character. Superman, to me atleast, is a sign that there exists hope and a greater good.

He evokes memories of a childhood spent looking up at the stars at night. Dressed in my red cape, I would stand on my terrace and dream away gazing at the twinkling above me. When I stretched out my arms and closed my eyes, I could fool myself for a moment…just a moment…that I could actually fly. That I could do all those amazing things he could.

That I could be a superhero.

He evokes memories of a childhood talking about superheroes and other galaxies with my father. I used to annoy my dad with questions like “How can nothing exist before the beginning of time? What is present outside the universe? What is the border between this and the outside?”. When I was not doing this, I would be seated in a corner of the house, busy with my paper and color pens, busy sketching away…Superman.

Superman returns.

Welcome back, Superman.

We missed you.


 

Find a friend


Orkut logo

From Greg Linden's excellent blog post, I ran across this Google paper ( Evaluating Similarity Measures - A Large Scale Study in the Orkut social network [PDF]) detailing how Orkut generates 'related communities'.

The actual findings of the paper do not hold much surprises. Cosine distance works as it should and it doesn't seem to penalize large communities much. By 'penalizing', I mean that if community A or B is real large, there is lesser chance of them showing up as 'related' though they may have Orkut members in both communities.

The paper makes some interesting observations on how much importance to give to whether a user joins a community when he views it by clicking on it in the 'related communities' section. In retrospect, this is pretty obvious - users are shy of joining communities which may 'embarass' them somehow (since all users can see what communities a user is part of).

I'm surprised that Google didn't go the extra step and try and find 'related people' using a similar measure. It would be fun to get a list of people you might be interested in talking to where 'potential interest' is determined by common communities, shared friends, degrees of separation,etc. A true 'find a friend' service. In fact, I remember Orkut's newsletter having something like this long ago - I wonder why they scrapped it.

On a tangential note, I once used the Del.icio.us APIs to try and build a recommendation system ('If you liked this page A, you may also like this page B since other folks who liked A - liked B too'). Unlike Orkut, del.icio.us has too much of a geek/early-adopter leaning. Maybe they will get a healthy influx of normal people due to their Yahoo acquisition.

Btw, if any of you find this stuff interesting, do check out George Karypis' paper - 'Evaluation of Item-based Top-N Recommendation Algorithms'.

P.S Orkut must be only Google service to run on Asp.Net (Writely doesn't count as it is an acquisition). However, I'm not sure whether such a donut-starved server is a good advertisement for Scott Guthrie's team :-)

P.P.S Before someone points it out, yes, I'm a Microsoft employee running a blog powered by Google's Blogger which is hosted on a Linux/Apache webhost. Why? 'Coz a friend already had some space which I could share easily. And Wordpress, the only other option I investigated seriously,had one thing I didn't like - it didn't generate static html pages. I know other blog engines do but I was too lazy to go use one of them. So shoot me :-)




 

WinFS - Death and Resurrection

WinFS


Quentin Clark, PUM for WinFS has just posted something which will probably show up on Slashdot in a few hours. I already see a storm brewing in Techmeme. You know it is important when Mini links to it :-)

Disclaimer - I've never worked on WinFS and my only involvement was lunchtime conversations about it with Pooja back when she was in the WinFS team.

I understand the need for changing the ship strategy but there's this little geek in me that wishes otherwise. After the tantalizing glimpses of WinFS at PDC 2003, my mouth watered at the prospect of a filesystem in a database.

Why? Because it throws opens possibilities that are a pain using today's filesystem metaphors. The idea of 'linking' an item to another item anywhere across the operating system was worth dreaming about.

This thinking lead me to start working on a Thinkweek paper for BillG last year. My basic premise was that there was value in investigating whether such a database model for a filesystem would work on your typical Windows Mobile device. My basic thrust was around the fact that these devices have primarily Outlook-like data all the time. However, as a developer, I jump through hoops of abstractions to get at this data (the hoops are much less in number if what you want is inside Outlook Mobile).

However, this paper never materialized unfortunately. Something called 'work', as is its wont, got in the way and I got distracted by my other Thinkweek paper (which I managed to see through to completion).

However, all is not lost. Ado.Net vNext 'Entities' slices through a lot of the abstraction problems that WinFS was supposed to solve and DLinq, in my opinion, is probably the biggest data programming innovation of the decade.

Back to WinFS.Will we see a database filesystem someday? I'm sure we will. When? I don't know. Perhaps sometime next decade - I don't know. But the prospect is too mouth-watering for any geek to resist (and the evidence for this is the number of attempts Microsoft has made at this - from Cairo to WinFS).

And Microsoft has a lot of geeks. Someone will make it happen.

It is just a question of time.

 

Bye bye CRT. Hello LCD

LCD Monitor



I finally got to do today something I've wanted to do for a real long time. I went to the local computer store and treated myself to a 19 inch LCD monitor for my computer setup at home.

Though I've a monster 21-inch at office, my home PC has always suffered from an inferior complex due to the 17-inch CRT monitor I used. Well - inferior no more!

Unfortunately, I can't use my old CRT monitor as part of a multimon setup yet as my ageing graphics card doesn't support dual output.

I plan to fix that next week by treating myself to - you guessed it - a spanking new GeForce 7 series card.

Now excuse me as I drool over how good my new monitor looks.

 

A brand new day




A


Hello everyone!

After several months (and even years) of contemplation, I've finally decided to take the plunge and be in the same league as Google, Microsoft or Yahoo - own a domain name and some webspace :-)

Why?

Well, all the cool kids have one. Seriously, the real reason is that I'm tired of hunting for space online to keep my various virtual knick-knacks.

The bigger reason is that I was uncomfortable about blogging non-technical stuff at my blogs.msdn blog. Of course, no one inside the big house has ever questioned any MSDN blogger on why he or she is blogging about their weekend trips. But it just felt wrong for me to use up Microsoft's bandwidth and web space to indulge my own pet literary fantasies

Are you going to kill your MSDN blog?

No.

My plan is to cross-blog all technical and Microsoft related writing.

Which blog do I subscribe to?

If you ask me, I would say this one :-). It's upto you - if you want your irregular dose of technical MSFT employee Sriram Krishnan to be unadulterated with accounts of his Quake IV exploits or his musings on the software industry and life in general, stick to the MSDN blog.

But give this blog a shot first


Bryan Adams - Here I am


...
Here I am - this is me
There's no where else on earth I'd rather be
Here I am - it's just me and you
And tonight we make our dreams come true

It's a new world - it's a new start
It's alive with the beating of young hearts
It's a new day - it's a new plan
I've been waiting for you
Here I am
...


 

Sheer beauty - how do you poll?

[Originally posted at http://blogs.msdn.com/sriram/archive/2006/06/08/621542.aspx - go there for the original comments]


From time to time, you see an algorithm or a technique that makes you marvel at the sheer beauty of it.

Barry Bond(who is our in-house emulation God, architect and chief troublemaker all rolled into one :-)) posted about the improvements that he and his team made to the emulator to speed it up by a whopping 40% from its first version to the second.

As a part of the team, I've been privileged enough to see check-in after check-in and to see the emulator team chip away at performance hotspots. For anyone interested in profiling or just in making their code faster, definitely go read that post.

There's a little innocuous section where Barry talks about how they poll for interrupts so much faster now.

The problem is simple - you have some stuff that can happen asynchronously. How do you poll(assume that polling is the only option for a variety of other reasons) and see whether anything has happened or not? What is the fastest way to poll? How frequently do you poll?

The typical implementation is what Barry and his team used in V1 of the emulator. The mainline code runs this code at a pre-determined granularity (at ARM instruction boundaries in the emulator's case) and the asynchronous event(the interrupt firing in the emulator case) is in charge of toggling fSomethingHappened (which is usually volatile since this is typically a multi-threaded scenario). I've listed the assembly I got after compiling this with full optimization. I've stopped the DoSomething function from getting inlined for the purpose of making this clearer.

    volatile bool fSomethingHappened=0;


int _tmain(int argc, _TCHAR* argv[])
{

if(fSomethingHappened)
{
DoSomething();
}

return 0;
}


mov al,byte ptr [fSomethingHappened (40336Ch)]
test al,al
je wmain+0Eh (40174Eh)
call DoSomething (401730h)
xor eax,eax

You have a compare and a jump. Now, jumps are expensive and generally a bad thing. How do we get rid of the jump? In fact, how do we poll..without using *any* instructions at all?

Let's say I gave you a guarantee - that the stuff you need to do inside DoSomething when something happens is going to take a lot of time - so you don't need to optimize for that case. You only need to optimize for the common case - that is nothing happening and fSomethingHappened being false.

In this case, we can do something really interesting - we can make the code in the asynchronous event firing responsible for *adding* the code to handle it as well.

How? See below
__declspec(naked) void DoSomething()
{
__asm
{
ret;
}
}



int _tmain(int argc, _TCHAR* argv[])
{

DoSomething();

return 0;
}

DoSomething:
ret

wmain:
call DoSomething (401730h)
xor eax,eax

This seems really weird at first glance - you have empty functions that are not doing anything. That's because the event patches the function with the code required to handle the interrupt

Here's the flow

  1. Thread 1 calls DoSomething. Returns instantly.
  2. Event fires on Thread 2 - so the event firing code patches DoSomething with a jump to the right code/the right code itself.
  3. Thread 1 merrily tries to poll again - calls DoSomething and handles the event. Life is good.

Check out how low cost the polling is in the normal case -when no event is being fired, we just do a call and a ret. But I hear some of you screaming - but you're still using 2 instructions.And why a call and a ret when you are not doing anything on the stack? You said you'll use no instructions! Well, you see, we actually are using 0 instructions.

It is due to the way processors speculate and look-ahead. All modern processors will look at the 'call' and see that it hits a 'ret' directly. They'll be smart enough to figure out that a call followed by a ret is effectively a nop - and therefore, turn the 2 instructions into a nop.

So in the normal case, the body of wmain for us is effectively this
wmain:
nop

When the event fires and patches the DoSomething function, processors realize that they cannot speculate anymore - and so they do the right thing.

Awesome, isn't it? Polling without actually executing the code to poll. Just sheer beauty - something that totally blew me away when Barry explained how this works.

Notes:

  1. You shouldn't be worrying about optimizations like this unless you are writing an emulator :-)
  2. The code for actually patching the function with the right code is left as an exercise to the reader :-)
  3. This code doesn't deal with issues like memory fences, atomic patching,etc
  4. Barry explained this to me when we were walking the Strip at Las Vegas. I know what you are thinking :-)

Archives

November 2004   January 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006   January 2007   February 2007   March 2007   April 2007   May 2007   June 2007   July 2007   August 2007   September 2007   October 2007   December 2007   January 2008   February 2008   March 2008