I'd guess that he prepared this, at least partly. He's done other rambles like this in stand-up and sketch. More importantly, it'd be easier to learn than to wing it, make it this good, and tie in this many things. He just is able to one-take it because he's on top of his game.
Maybe improvised after lots of preparation, and years of geeky rambles on these themes?