Genealogy Update: Layne Edition

A few months back I attended a reunion for the descendants of Henry Miller Layne where the desire to document my ancestry was reawakened after a long long slumber. My initial “research” consisted of little more than copying research originally completed by Floyd Benjamin Layne in the 1950s for his book Layne-Lain-Lane Genealogy. My focus then was geared more towards finding as many relatives as possible with little concern given to documenting my sources or trying to learn who my ancestors really were.

I wanted to change that this time around, starting with my oldest Layne ancestor, John Hiram Lain of Virginia. Given the amount of information that is available today, perhaps I could learn a bit more than old Floyd did back in the 1950s. I began by trying to learn more about John Hiram’s origins. Exactly when did he arrive in middle Tennessee and why? I didn’t make a great deal of progress just focusing on John, so I then starting learning what I could of his children hoping that perhaps that would turn up more clues as to the family origins. I discovered a good bit and thoroughly documented all I learned of John and his first two children, David and Elizabeth, but mostly what I learned was that Floyd Benjamin’s book is riddled when inaccuracies.

Before moving forward with his next child I decided to take a step back and fill in and correct some of the information from the book at sort of a higher level. I needed sort of a sturdier platform from which to do the more detailed work. When I began I had somewhere in the neighborhood of 350 Laynes with no birth information of any kind. This made it hard when searching my tree to figure out, for example, which of the 35 John, 34 William, or 17 Daniel Laynes I was trying to locate.

After several weeks of work I’ve updated information on hundreds of Laynes and Layne relations and I’m now only missing birth year information on only 81 Laynes. Now that that is complete I intend to get back to my original goal which was learning and documenting everything I can about John Hiram Layne and his children. Although I’m going to skip ahead next to Isaac Layne because Floyd Benjamin’s book appears to have a pretty significant mistake that I need to correct.

Hopefully I’ll have Isaac documented soon, but in the meantime if you find any errors or omissions, kindly point them out and I’ll correct them as soon as I can.

WWDCs Past (2015 edition)

Seems like this years WWDC announcement should but popping up soon. With that in mind I figured I’d post an updated WWDC announcement table. It’s getting to be a whole tradition now or something. Sort of goes with my tradition of not getting a ticket for the last few years :/

Year Announce Date Announce Day of Week Conference Date Week In June (full) Days Notice Time to Sell Out
2005 Feb 15, 2005 Tuesday Jun 6, 2005 1st 111 days n/a
2006 Mar 8, 2006 Wednesday Aug 7, 2006 n/a 152 days n/a
2007 Feb 7, 2007 Wednesday Jun 11, 2007 2nd 124 days n/a
2008 Mar 13, 2008 Thursday Jun 9, 2008 2nd 88 days 60 days
2009 Mar 26, 2009 Thursday Jun 8, 2009 1st 74 days 30 days
2010 Apr 28, 2010 Wednesday Jun 7, 2010 1st 40 days 8 days
2011 Mar 28, 2011 Monday Jun 6, 2011 1st 70 days 12 hours
2012 Apr 25, 2012 Wednesday Jun 11, 2012 2nd 47 days 1h 43m
2013 Apr 24, 2013 Wednesday Jun 10, 2013 2nd 47 days 2 minutes
2014 Apr 3, 2014 Thursday Jun 2, 2014 1st 60 days lottery
2015 April 14, 2015 Tuesday Jun 8, 2015 1st 54 days lottery
Announced on
Sun Mon Tue Wed Thu Fri Sat
0 times 1 times 2 times 5 times 3 times 0 times 0 times

Swift Optional Chaining Performance

Optional chaining in Swift offers a convenient mechanism for testing an optional value embedded in a statement without having to bother with messy binding or dangerous implicit unwrapping. It’s basically just a bit of syntactical sugar that internally converts something like this:

foo?.bar = 42

into this:

if let unwrappedFoo = foo {
  unwrappedFoo = 42
}

This is fine when used in moderation. However I occasionally run across code like this:

foo?.bar = 42
foo?.baz = 3.14
foo?.doThatThing()

This makes me a little itchy. My worry has been that the compiler then generates code as if it encountered the following:

if let unwrappedFoo = foo {
  unwrappedFoo.bar = 42
}
if let unwrappedFoo = foo {
  unwrappedFoo.baz = 3.14
}
if let unwrappedFoo = foo {
  unwrappedFoo.doThatThing()
}

You would (hopefully) never write something like this but that’s how the compiler is going to interpret all those chained optionals… Or is it? Maybe the compiler is smart enough to figure out what is going on here and I should just relax and let it do its thing?

Nah, I need to know what’s going on. So I cobbled together a few contrived examples in Xcode and ask it to generate some assembly for me… Except Xcode can’t yet show you the assembly for a Swift file. Sigh. Okay well Google can probably tell me how to look at the assembly and sure enough I find this lovely article (which, by the way, also introduced me to Hopper which is pretty awesome).

Armed with Hopper and a bit of knowledge I set about examining the assembly produced with a variety of techniques and optimization levels with my sample code.

My first test was an unoptimized test of a function using optional binding versus the equivalent using optional chaining (letTest vs chainTest in the sample code) and which yielded assembly with the following lengths*.

Unoptimized Opcode Count
Optional Binding 138
Optional Chaining 248

As I suspected, the optional chaining was much less efficient. Not really surprising, until I examined the same functions with optimizations turned on.

Optimized Opcode Count
Optional Binding 87
Optional Chaining 82

Wait, what? The compiler was somehow smart enough to figure out what I was doing and doesn’t just match the optional binding approach, it beats it. Looking over the assembly, it appears the optional binding approach included an extra retain / release.

After the first batch of results the relaxed approach is starting to look better. Maybe I just hammer on the keyboard and the compiler somehow just figures everything out for me. But first another test. This sample is identical except these are methods instead of global functions. First the unoptimized results.

Unoptimized Opcode Count
Optional Binding 147
Optional Chaining 195

Actually a bit more respectable here than the global counterparts, but optional binding is still much more efficient. And the optimized results…

Optimized Opcode Count
Optional Binding 102
Optional Chaining 132

Interesting. This is what I expected originally. But why the difference between a method and the function? I imagine because the variables could have setter functions or observers which could alter the value of tObj, therefore the compiler can’t be confident that it does not have to test the value of tObj for each assignment.

In the end, using a series of optionally chained statements is not horrible and in at least one case actually faster than optional binding, but personally I’m going to continue to do what I can to provide those additional clues to compiler and future maintainers of my code (including myself) as to my intent where practical.

Of course this just goes for a series of optionally chained statements. If I’m only evaluating that optional once (maybe even twice if I’m feeling naughty) then optional chains are perfect. Any more than that though and it’s getting wrapped in an optional binding.

*Using the length of the generated assembly as a measurement of efficiency is not always the best idea. The compiler could be unrolling loops or any number of optimization techniques that don’t end up generating less code. However this example is pretty simple and serves as a decent yardstick here.

A Few Toys

Since the release of Terrella and the big update to Super Speller I’ve slowed down a bit with Quiet Spark work. But that doesn’t mean I’ve completely stopped working on personal projects. There are a few things over on github that I’ve been picking at here and there as the mood strikes me.

First I have a Swift based video poker app for iOS. It’s called Poker. Clever eh? I’m not sure I would use any of that code in anything real since it was mostly a testbed that I used to teach myself Swift. Very basic. Except maybe the expected value calculations that I added. There are probably more efficient ways to calculation EV. I just used a brute force method, but I was trying out different ways of iterating over objects and evaluating ~1.5 million poker hands was a good way to put Swift through its paces.

Next up, a very simple app to try and find bundle and sandbox locations of apps installed on the simulator in Xcode 6. What with the fifty-eleven different simulator configurations I understand why Apple decided to rework the simulator locations. I’m not sure why there isn’t an easy way in the simulator or Xcode to get to these locations though. So I wrote SimDirs (another clever name) to try and track these locations down. I’ve not been able to find a 100% reliable way to do this though. Feel free to improve upon it.

Finally, I’ve been trying to do a better job giving back to the developer community, hence the recent activity not only on github, but also StackOverflow. I try to keep this stackoverflow page open and skim through the questions as time allows. But what I really wanted was an app that would let me see new questions and hide those I’d looked at and/or ignored. So I wrote… wait for it… StackMonitor. Again, nothing fancy. I’ve not even put this one through its paces for a whole day yet actually, so who knows how well it’ll work in practice.

The SimDirs project has actually seen a bit of interest so I was motivated to try and make it a bit better. There’s definitely still room for improvement so I may continue to pick at it and the others as the mood / need strikes me.

Tracking Down Storyboard Warnings

Xcode seems to have this annoying problem where sometimes, most of the time for me, when I select a storyboard warning it will open the file, but won’t show me the item that’s affected. This is becoming a real problem now that layout margins and Automatic Preferred Max Layout Width on UILabels seem to be the default.

Reveal compiler output
Reveal compiler output with this thingy

I’m working on a project that contains a pretty huge storyboard where trying to find the culprit would be like looking for a needle in a haystack. Fortunately I discovered a trick. Not sure trick is the right word but whatever. Here’s what you do. Switch to the Report Navigator and select your most recent built. Make sure “All Issues” is selected and locate the storyboard that contains warnings. Then click the hamburger looking button to the right to see the compiler’s actual output.

Storyboard IDs
Compiler output shows the storyboard IDs

After expanding the compiler output, you should see a list of your warnings towards the end. These warnings include the storyboard path along with an identifier and the warning text. Copy the identifier for the warning that you want to investigate and then paste that into Find In Workspace (⌘⇧F).

Find In Workspace with storyboard elements
Find In Workspace with storyboard elements

Voila! Xcode should display the problem storyboard element as a result. When you click on the result it will open the storyboard and select the element in question allowing you to fix the edit.

Maybe this is a thing everyone already knows about but it was news to me when I accidentally stumbled across it a little while ago. Hopefully you find it useful.