WebGL performance

June 16, 2011

It turns out the performance problem I mentioned in Chrome is entirely down to Float32Array. Known problem, apparently. In particular it looks to me like garbage collection, as it only shows up every few dozen frames (few hundred in less geometry-intensive cases).


June 14, 2011

I’ve been learning about WebGL recently, not that I have any particular reason to use it. My first experiments, selected mostly because they look neat, are here:

  • A Julia setA Hopf fibration viewer. The Hopf fibration is interesting and important mathematically—it’s part of the reason homotopy theory turns out to be so much more complicated than homology, for example—but its real importance to me is that it makes for great pretty pictures.
  • AMandelbrot set “explorer.” That’s the first thing everyone does when they learn about shaders, right?
  • A Julia set explorer. It turned out far trippier than I had hoped for.

I’m comfortably certain these are not models of good WebGL practice. (Or good html/javascript practice, for that matter).

So what have I learned? For starters, half the people I’ve tried to show these things to can’t run them, for whatever old-browser and old-graphics card/driver reasons. How long will it be before you can reasonably assume any random user is likely to be able to use this stuff? I suppose it does make sense to learn it now so as to be ready in five years when it’s generally supported. Or maybe it’s that the primary audience is gamers, happy to have an excuse to buy a new graphics monstrocard every few months.

As for the thing itself, it’s interesting comparing it to what little I remember from the days when I knew OpenGL. From a high level it’s pretty much what you’d expect from a translation of OpenGL, or a stripped-down version of it, into javascript, the most obvious difference being that you have to provide your own shaders. I’m rather glad to have to reason to learn about shaders, really; they’re new since my day.

I haven’t figured out all the nuances of GLSL. As an example of the sort of thing I’ve run into, the Mandelbrot fragment shader has a big loop to count iterations. for-loops in GLSL must be of a form like

    for(int i=0; i<CONST; i++) {

where CONST is some actual constant—I assume, possibly wrongly, that that’s so loops can be implemented by unrolling. That I learned quickly enough. Where I ran into problems was figuring out what the CONST could be. Some machines, at least older ones, seem to have a cutoff of 255, and behave oddly (it doesn’t look like a simple mod, but I haven’t tried to figure it out) if the bound exceeds that. The GLSL spec (which appears to be somewhat out of sync with what WebGL as implemented uses; am I looking in the wrong place, or otherwise missing something?) wasn’t much help there.

Back to WebGL vs. OpenGL in general, the other immediate difference is that there’s no more glBegin/glEnd: you have to do everything with buffers. That seems to add to the boilerplate. And of course a lot of the familiar OpenGL and glu methods for things like matrix handling are missing, so you have to provide them yourself. Or find a library that does them all. I don’t think I particularly like either of the ones I’ve seen, but haven’t really thought about them much yet. I can see performance being an issue with getting libraries right.

And finally it’s a bit annoying that WebGL only knows from floats, not doubles. That rather surprises me, but I don’t know enough about this stuff to rant without making a fool of myself.

As long as I can stick to my machine, a relatively beefy Macbook Pro, I’m impressed by how well this stuff works, despite the whingeing above. I haven’t done any real stress tests, but what I have done seems to work well and quickly. As expected, both chrome and Firefox support it. Interestingly, the Firefox implementation seems to be noticably more performant than Chrome. During animations Chrome seems to seize up (garbage collecting?) every couple of seconds. Firefox is nice and smooth.


Rambling Thoughts about Comonads

December 18, 2010

[Slightly revised since first posted.]

This entire post is, or is intended to be, a Literate Haskell file. You can copy-paste the whole thing into an .lhs file and run it with ghc (I vouch for it only in version 6.12.3). Some caveats: I am not a Haskell programmer. At worst you should suspect everything I say of being, well, wrong, and at best I’m comfortably certain the code in here is not as elegant as it ought to be. Apologies for all the references that I neglected to include either out of ignorance or out of laziness. And as will be clear I’ve been awfully sloppy throughout.

A while back I started thinking about comonads. I now have little idea why—“a while” is nearly two years—but I think I must have been troubled by the apparent lack of symmetry between monads and comonads in functional programming. It seemed somehow ufair that monads are so useful and get so much attention, while their poor duals are neglected. Really I just wondered whether some of the standard monad constructions and connections—monad notation, most obviously, and the connection with Applicative Arrows—had any dual consructions, and whether they might be useful. It turns out they there are indeed dual constructions, although I suppose I can’t truly swear to the usefulness part. Herein are most of my collected thoughts on the subject.

BTW, I have little idea how much of what follows is original, but a couple of things way down below the fold might be. You can easily find a fair bit about comonads and examples thereof, but I haven’t seen either real proposals for comonad notation (not that I’m claiming there’s one of those here either) or anything about “Coapplicative Arrows” elsewhere.

Read the rest of this entry »

Pride and Punctuation; or, Sense and Semicolons

October 28, 2010

As if it’s not enough that Shakespeare’s plays were written by the Earl of Oxford1, now we find that Jane Austen’s style was not her own, but rather the work of William Gifford, apparently the Best Editor Ever. Or so says Kathryn Sutherland, Director of the Jane Austen Manuscript Digital Edition. According to some of the many accounts (h/t: I first heard of this in a comment here),

"What I’m particularly interested in is that the manuscripts do not bear out that high degree of polished grammatical style for which Jane Austen is known"—what Ms. Sutherland calls "the exquisitely placed semicolon."


In particular, the high degree of polished punctuation and epigrammatic style we see in Emma and Persuasion is simply not there.


One of her grammatical errors was the inability to master the ‘i before e’ rule and her works were littered with distant ‘veiws’ and characters who ‘recieve’ guests.

On other occasions she wrote ‘tomatoes’ as ‘tomatas’ and ‘arraroot’ for ‘arrowroot’, which according to Professor Sutherland reflect her regional accent.

‘In some of her writing, her Hampshire accent is very strong. She had an Archers-like voice with a definite Hampshire burr,’ she said.

For some healthy skepticism about such claims see Language Log and Austenblog, with good comments to be found at both. I don’t have much to add, just to reinforce that the only real specifics in the reports are about spelling and punctuation—in rough drafts!—which really don’t detract from her “polished grammatical style.” Unless, I suppose, you’re Lynne Truss.

It’s always nice when the evidence for these bold claims is easily available online; so I had a look for myself at this new Jane archive. I have to say it’s pretty neat: whatever the merit of Professor Sutherland’s claims, she and her colleagues seem to have done great work amassing and transcribing and presenting all these manuscript pages.

The first problem in deciding what to make of Professor Sutherland’s claims on behalf of Mr Gifford is that there is virtually nothing in these manuscripts to compare with published versions. That’s right, not only are these all rough drafts, there rough drafts of things that weren’t even published. Apparently she didn’t bother to keep either rough or fair copies of the ones that were published. The only exception is a bit of Persuasion, which looks to me to be very nearly identical to chapter 24, minus the very end, of the published version (at least as it appears here), with fewer commas and more dashes. It is fascinating to look at what she crossed out and rewrote. The most interesting bit is a passage about Sir Walter Eliot’s newfound respect for Captain Wentworth, pasted over in favor of what I think is a rather less piquant version. Perhaps she decided she had already been hard enough on the Bart., or more likely that it was a little repetitive with passages earlier in the book. But it is funny:

As he saw & conversed with Capt. W. more, saw his complexion by daylight — & perceived in conversation that his Teeth were as fine as ever. — he could not but feel that in any present comparison with Anne, Capt. W. must have the advantage, that he had lost much leſs of Youth & bloom than she had, and consequently might now

Back to Jane’s alleged unpolished prose and lack of “epigrammatic style,” I suppose that one could make an argument based on the style of all these unpublished (but hardly hitherto unknown) works as compared to that of the published ones, especially those that Gifford edited. [Which, by the by, do not include Pride and Prejudice and Sense and Sensibility and Mansfield Park]. Maybe that is what Professor S means to say, but if so I haven’t heard her say it.

Oh, and and typography! Or, um, not typography, but whatever you call the handwriting equivalent (I should really know the right word, shouldn’t I?). These manuscripts are full of long s’s, the things that look like a bit f’s but aren’t (they look like ſ, with no crossbar, or sometimes a little nub on the left; italic ones generally look like integral signs; and they are simply an alternate form of plain old “s”). Jane seems to have been much more regular than many printers in her use of long s, her rule being (as far as I can tell) just that ss is always written ſs. Anyway, I had never seen any manuscript long s’s before. It turns out that they look like f’s (surprise!) with the bottom loop reversed. That would make them quick to write, I should think, with no stroke reversals (is there a technical term for that?). Here’s the word “less”:


Neat, huh? Well, I thought it was interesting.


1. That’s ridiculous, of course. Shakespeare’s plays were written by Mary Sidney Herbert, Countess of Pembroke.

Vampires! Mostly, sort of.

October 26, 2010

When I was a boy I watched a great many science fiction and horror movies on TV programs with titles like The Big Show, Creature Feature (with Sir Cecil Creape), and Dr. Shock (“Good night, sleep tight, and should you hear a scream in the night…it will be your own.”)

Sir Cecil. I couldn’t find Dr. Shock.

Ah, youth! I doubt a single one of those films could have been called “good” by any reasonable measure, but for good or ill—mostly ill, I should think—all that schlock is deeply embedded in my soul. When I think of my childhood, at least of the fun parts, I think of bad acting and worse special effects. Happy days indeed!

And now, thanks to streaming Netflix, I can relive those golden days. I have no idea what I was looking for last weekend when Netflix decided that I might like Queen of Blood (usually it has me pegged, correctly, as pretentious). I was a little nervous about watching it, not wanting a fond memory ruined, but I was pleasantly surprised to find that it was exactly as I remembered it. Which is to say, pretty bad, but in a good way. It was too cheap to have its own special effects, so it stole some from a much more expensive and possibly much sillier Russian movie. I like that.

I'd rather meet one of the green girls from Star Trek In the distant future, the year 1990, the International Space Federation (whose signage has lettering that must have looked very futuristic in 1966) has received radio transmissions from an alien race and is eagerly awaiting the arrival of emissaries from same. When the alien spaceship crashes on Mars, the ISF dispatches a rescue mission, including Manly Astronaut John Saxon; his girlfriend, Sexy-Girl-Next-Door Astronaut Judi Meredith; and Expendable Astronaut Dennis Hopper, looking very young in his pre-Easy Rider days. They find the crashed spaceship—it turns out to be on Phobos, for reasons that probably have to do with the Russian footage the filmmakers cribbed—with a single survivor, an exotically green-skinned alien woman, played by exotically Czech actress Florence Marly.

Well, wouldn’t you know it, she turns out to have a taste for human blood, and to have both hypnotic powers and heat vision, which prove awfully inconvenient for Hopper and the mission commander (who will have to remain anonymous here, as I’ve forgotten his name). Fortunately, our better-looking heroes make it back to earth, where (twist ending! there’s always a twist ending) they discover that the alien has laid eggs throughout the ship. She really was a queen, the egg-laying kind of queen, get it? Beware, humanity!

Like so many Roger Corman-produced cheapies of the era, Queen of Blood makes the most of its small budget and low production values, making up in spunkiness what it lacks in, well, everything else. And it does have a few moments of great creepiness. Marly, who seems to have been a sort of minor Marlene Dietrich, did manage to project some real eeriness, even completely silent and wearing a space helmet over a hairstyle that must have looked silly even in the sixties—another legacy of the Russian donor movie, I think. And the final scene, of enthusiastic scientist Basil Rathbone (yes, really!) beaming as he carries trays of alien eggs off the spaceship, is nicely chilling.

Mark, Bert, Wes, and the gang Flush with the success of QoB, I moved on to Planet of the Vampires, which I remember being very scary indeed. I had high hopes for this one, for reasons beyond my childhood fears. For starters, it was directed by Mario Bava, the Italian horror maestro who brought us such horror classics including Hatchet for the Honeymoon and Black Sunday (which scared the piss out of me when I was six, and which is tragically unavailable on instant play). And according to Leonard Maltin and the internet it has a reputation for stylishness.

Alas, the maestro let me down. PotV is merely so bad it’s bad. The vaunted Euro-style is mostly low light, a lot of wasted space in the spaceships’ control rooms, and a dry-ice fog machine in the “eerie planet” set. The dialog is sub-trite, except for the technobabble, which was all babble and no techno. The spacesuits are among the silliest in all of sci-fi. The astronauts are named “Mark,” “Wes,” and “Burt.” At least the High G special effects—actors (if you can call them that) putting their heads on their desks, basically—were worth a laugh.

And there are no vampires. Instead, there are evil alien spirit beings that force the astronauts to kill each other, and then possess the corpses. Which wouldn’t be bad, actually, if only they were scary. There is one almost-good sequence in which the astronauts find centuries-old wrecked spaceship, the occupants of which apparently fell prey the the evil spirit beings. Was it an inspiration for Alien? I would think so, but it’s a little different to imagine the two being connected. Alien was, you know, really good.

I fear I gave up on PotV. Maybe I’ll go back and watch the end, the bit that really got younger me: (SPOILER ALERT) we find that the last two “survivors” are in fact not survivors at all, and that their alien possessors intend to spread their evil race throughout all civilization. But, the ship’s Meteor Rejecter having been irreparably damaged, they are forced to land instead on a nearby undistinguished planet with a primitive situation, a planet called (wait for it…) Earth!

Enough of these space vampire movies with no vampires! It’s time to get back to real vampires.

Finally, a REAL vampire. I’m pretty sure I never saw The Vampire Lovers, certainly not in all its unedited glory, but I saw a great many others from Hammer Productions. Hammer’s films were earthy, violent and bloody. They took little interest in afterlives or other worlds, except as they might lead to the immediate leaving of this one, preferably gruesomely. As a friend of mine put it, “In a Hammer film, you could die.” Hammer vampires, starting with Christopher Lee’s Dracula, were foul and brutal creatures, not in the least soulful or tormented or sparkly.

The Vampire Lovers dates from the happy time when Hammer, like other production companies, had just discovered nudity. And what better use for nudity than a Victorian lesbian vampire story? The Vampire Lovers is an adaptation of J. Sheridan LeFanu’s Carmilla, the lesbian vampire story from which all other lesbian vampire stories derive. I read it long ago, and remember its being disappointingly tame and a bit boring, as I suppose befits something from 1872. You can see for yourself here; I haven’t had the energy to reread it.

The movie is surprisingly (though certainly not strictly) faithful to the story, and really a great improvement, what with the nudity and the explicit lesbianism and the general Hammering it up. Carmilla, aka Mircalla aka Marcilla (aka Millarca in the book) is played by Ingrid Pitt, who made a bit of a career of this sort of thing. I have no idea whether she could really act, but she was so sultry (dressed or not) that it hardly mattered. The plot was not particularly coherent, and a number of things were left unexplained and unresolved (maybe the book was the same way), but again, who cares? Plot coherence really wasn’t a Hammer value. Hammer movies were about fangs and blood and terror. And nudity.

So if she weighs the same as a duck…

February 1, 2010

She does look very calm about it. From yesterday’s Boston Globe, here’s an article by economist Peter Leeson arguing that medieval trial by ordeal was really not so bad. The article is notable for its complete lack of anything resembling evidence, but there is a little—very little, but more than none—in Leeson’s academic paper here. I think the most interesting bit of that is the contention that men and women were treated differently: men, typically with lower body fat and hence more likely to sink when tossed in a pond, were more likely than women to be given an ordeal by cold water, in which sinking was interpreted innocence.

The basic theory (tarted up with equations in the paper) is that (i) people who actually believed in the efficacy of ordeals would submit to them only if they were indeed innocent, confessing or settling or running away if they were guilty, and that (ii) the priests who ran the ordeal process would rig the results in favor of the innocent accused. I’m not sure the first point would apply to capital cases, much more common then than now, given that a guilty person, presumably already condemned in God’s eyes, would have little reason not take his chances on the ordeal. And as for the second point, well, I am not convinced that medieval priests were universally known even then for their honesty and incorruptibility.

A couple of years ago Leeson wrote a book about economics and pirate democracy that I keep meaning to read. I hope it’s a bit more convincing than this…


January 24, 2010

[Mild spoilers, but probably nothing you don’t already know if you’re bothering to read this…]

Mother of the Cylons

Finally saw the pilot of Caprica today (huzzah for HD TiVo!), and I have to say, it was pretty frakkin’ great. I’m really not sure what I expected, apart from “Battlestar Galactica prequel, with proto-Cylons,” but I’m pretty sure it wasn’t what it turns out to be. (Well, OK, it did have proto-Cylons, which I admit brought a nostalgic tear to my eye. Kind of like the half-finished Death Star at the end of Revenge of the Sith.)

Apparently the story was originally nothing to do with BSG, but the good people of SyFy have done a surprisingly good job shoehorning it in to the pre-existing framework—(ur-)Cylons! Gods! Retro-hip clothing! “Frakkin’!”—and more importantly of continuing the BSG tradition of moral ambiguities and inversions.

The techo-babble doesn’t bear too much thinking about, but you didn’t really expect it to, did you? And it all goes down pretty easily thanks to some excellent production design (I suppose I should be pretentious and refer to mise-en-scène here). As in BSG the design is all “earthlike”; no wild Star Trekky aliens and costumes on Caprica. It reminds me a bit of a great line from Babe: Pig In the City: it’s set “a little to the left of the twentieth century.” The Caprica City backgrounds reminded me a little of old matte paintings from movies set in the not-too-distant future Year 2000, except of course in nice sparkly HD; I’ve always been a sucker for matte paintings. The actors were reasonably good, especially Alessandra Torresani, in what I imagine is the most fun role in the series. That’s her in the picture, being Eve, in case you missed the Gnostic relevance of her character’s name.1

I’ve no idea how long it will take Caprica to run out of steam, as I’m sure it will. It took BSG about a season and a half before it started becoming obvious that the writers were starting to flounder. I’ll take a season and a half of this.

1.  See also Genesis 3:20 in the Septuagint.

Corporations are Persons, Money is Speech, Ignorance is Strength

January 24, 2010

I haven’t actually tried to read the decision in Citizens United v. FEC—it’s long (looong) and written by the odious Anthony Kennedy, whose pompous arrogance, untempered by Scalia’s savage and entertaining wit or by Thomas’s clarity and brevity, pisses me off—and if I did it’s not like I’d really be a reliable interpreter, not being a lawyer and all. But, well, jeez.

I’m trying to buck up by telling myself that

  1. This will merely make advertising more honest; corporation already contribute pretty much whatever they want to political campaigns, they just have to weasel through loopholes;
  2. Political advertising makes less difference than people think, and we’re pretty much saturated as is; and
  3. Let’s face it, existing restrictions on campaign finance do suppress speech.

But no, I’m not buying any of that either.

From what I’ve read about the decision (from which I may admittedly have drawn wildly inaccurate conclusions, see above) I think the real problem with it is that it doesn’t acknowledge the principal-agent problem. Owners of large corporations—that’s all of us who own stock—do not have any input into those corporations’ political advertising. It’s our agents—the officers and boards—who decide that, and their incentives are wildly different from ours. I certainly don’t want corporations I own stock in to be spending anything at all on political ads, but my wish makes not one whit of difference.

If the world were otherwise ordered, then maybe shareholders would control in some meaningful sense how corporations behave. The fact that such is not the case, and really can’t be, is exactly the sort of real-world inconvenience that Anthony Kennedy can’t be bothered with. How I miss Sandra Day O’Connor.

On the Bright Side

January 21, 2010

Joe Lieberman and Ben Nelson are completely irrelevant now, right? The Democrats can get just as much nothing done with 57 votes as with 59.

And maybe, just maybe, Harry Reid will grow a pair. Or, since that’s not going to happen, step down in favor of Schumer, who already has one.

I hope the Democratic “leadership” is watching Jon Stewart; watch the whole thing, or start at about 6:30.

Martha Oh Dear

January 19, 2010

I’m trying not to get depressed about today’s election until it actually happens, but it’s difficult. The hope I’m clinging to is that the polls are basically worthless because of wild self-selection bias. Those of you not in MA have no idea how annoying this last week has been, with constant calls from both sides. Any reasonable person’s first response to any poll at this point would be a string of obscenities. I don’t know how I’ve managed not to rip the phone out of the wall yet. God knows what that does to the responses.

My pre-post-mortem is pretty conventional. After a reasonably good campaign in the primary, Coakley (and her handlers, who deserve a lot of blame here) assumed she’d coast in the general, and effectively shut down her campaign. That allowed Brown to get out his base—MA may be the Bluest of Blue states, but all states are really Purple, and we do have a big Republican base here, ready to have its blood angried up (see also this). When a couple of polls showed the race getting close, the Republicans smelled blood and the Democrats panicked. Panicked Democrats are even less competent than calm Democrats, and Coakley’s ads over the last week are starting to turn even me against her. She can’t seem to decide whether to campaign against Bush and Cheney or against Operation Rescue, and neither makes a particularly good target. Yeah, we all hate W and Dick, but we’ve all noticed that they’ve been out of office for a year now; and the abortion thing is based on obvious exaggeration to the point of, well, lies. So, feh.

UPDATE: Apparently turnout is heavy, which (i) is likely good for the Coakley, since she’s a Democrat in a Democratic state, and (ii) means the polls are probably crap, since they assumed the low turnout appropriate for an off-election in January. Say what you (and I) will about all those vile robocalls, at least every last person in the state knows there’s an election today.