Thursday, October 31, 2013

8092.5

So, just over 225 miles this month, which is not bad, given the number of days where it was wet, or I needed for one reason or another to work from home. So 2500 (2932) cumulative; with 2750 on my bike being what looks like a good stretch goal for the year.

Sunday, October 13, 2013

Some observations on performance

When I was at the barbers' the other day, the puzzle section of the newspaper had a word game that involved taking a 9 letter word and using the letters to fill in a degenerate crossword box with 1 Across being 5 letters, and 2 Down also 5 letters, starting at the 3rd letter of 1 Across. So naturally, I thought "I can write a script for that", so I did.

My first take used Set operations because the target word had no duplicate letters; so I thought, "let's generalise this, and tidy up the scruffy looking bits" so I could get all the possible variations.

Which left me with this


which ran like a slow thing in SlowTown -- it took a few minutes to scan 97 words beginning with "ab" and yield 9 words with a unique decomposition.

As my original take hadn't seemed to run anywhere near as sluggishly, I reverted all the Seq.choose and match to Array.filter and Option.isSome and got an order of magnitude speed-up.


So how much faster could I make it? I tried a lot of things -- everything as a seq, cache the sequence form of the words, adding a look-up table so given one five-letter word, I could look up a precomputed list of ones starting with its third letter, -- but the times all stuck around the 10 second mark for the "ab" words (or got worse, like when I cached the result of taking the five letter word from the 9-letter one).

The only thing that made any positive difference was replacing the immutable structures in the test for whether a word was a subset of another, like

That got about a factor of 3 improvement, and worked through all 10803 9-letter words and 4717 5-letter ones to yield 1942 candidates in about eight and a half minutes.

So I'm baffled about what is making the slow case so slow, but I'm making this note about it here in case I hit it again.

This was all done on my '07 vintage laptop using F#3.0, with the word list I got through Stack Overflow, for those who want to try out timings. A British word list, of course, for a puzzle in a British newspaper.

Saturday, October 05, 2013

PowerShell 3 Start-Process MSBuild.exe -Wait hang

Having recently upgraded a Win7 machine that I had previously been using to check PoSh 2 compatibility (and had forgotten was not upgraded) to PoSh3, a build script launched from a PoSh prompt that did Start-Process MSBuild.exe -Wait -PassThru - ArgumentList ... started hanging on the wait more often than not, with Process Explorer showing the MSBuildTaskHost executable still lingering outside of the PowerShell process tree.

Killing that MSBuildTaskHost process usually unwedged the process, so it could go on to do the post build analyses in the rest of the script. Running with DISABLEOUTOFPROCTASKHOST=1 to avoid the separate process was worse -- there was no process around to kill and maybe release the PowerShell session when it hung.

Replacing the cmlet with a direct invocation & MSBuild.exe ..., and using $LastExitCode rather than the process object ExitCode property value seems to avoid the hang so far.

I don't know whether it's just MSBuild that's affected by this hang on wait, but I've not seen this behaviour elsewhere yet.