I was looking into how to optimize queries in Core Data and wrote some code to test the various ways. It turned out that creating Fetch Request Templates was faster but I had no idea why and wrote a blog post about the results I got in various ways to do fetches in Core Data. I ended up asking about this in Stackoverflow and at first didn’t get much of an answer at first. The next day, I ended up realizing the biggest of the difference between a regular fetch and running on via a Fetch Request Template was that programmatically creating a fetch request it’s required that we provide a sort (versus a Fetch Request Template which doesn’t require the results to be sorted). I was going to update the code to test this assumption and just got around to it.
After a few days of that question on SO going unanswered, someone put a bounty on it and the question got enough attention to get it answered by more experienced iOS devs. I never realized how useful a bounty was.
So as you can see in the screen capture to the right, most of the difference between a regular fetch and a template fetch is due to the absence of a sort. Once I put a sort on the template fetch it was almost as slow as a regular sort – still a bit faster. I’m not sure what the insert/update costs of a index on the sort are but indexing both the search field and sort field doesn’t help all that much. There is still a bit of a difference between a regular fetch and a template search but nothing like the difference in putting an index on the search or sort field.
Again, here’s the code if you want to test other things: https://github.com/jinyk/CoreDataFetchTests.
I’ve had back issues on and off for a while. Pretty sure it’s due to my horrible posture while sitting at my desk all day. I’ve tried doing mid-section exercises, stretches in the office, neither of which have helped much. Granted, I haven’t been really committed to either efforts. I thought I would give standing desk a try. I figured, once I’ve set it up, I won’t be able to really half-ass it. It’s only been a week so far but it’s been fun and from the strain on my mid-section I can tell it’s building up those muscles.
Second reason I wanted to try it was so I have an excuse to build something. I’ve been wanting to build a custom stand for my iPhone which is nice to be able to use with just my left hand during testing. The standing “desk” I built is really just a small table on top of my regular sitting desk. It’s mostly out of parts from Ikea. It’s basically this design found at A standing desk for $22 which I modified.
I wanted to make sure it had enough room for both my monitor and laptop so I used a wider LACK table. Also, their specifications for attaching the shelf brackets to the legs of a Lack table didn’t work for me. I used 2.5″ screws that extended almost all the way into the leg but I found it to not be enough support. Maybe the material Ikea uses for the legs have changed? I ended up having to use bolts, washers, and nuts to attach the shelf brackets to the legs. Now those suckers are on there real good. Here are the parts I used:
- 35 3/8″ wide LACK Coffee table $19.99
- 2 x EKBY VALTER Brackets $8.00
- 46 7/8″ EKBY TRYGGVE Shelf $7.00
- 4 sets of 3″ bolts and appropriate washers and nuts (Home Depot) ~$7.00
So all told about $42 before taxes. I’m not including the saw that I had to buy to cut the 46″ shelf to better fit the length of the LACK table’s width.
- Get a floor mat for standing. I stand barefoot so this really helps but I imagine even if you have shoes on, this probably helps. Luckily, I had one at home we bought for my kids but they never use. These from Hmart are pretty nice: Kitchen Mat.
- Do not attach the shelf to the bracket. I have other attachments to the table (maybe in another blog post) and I find it really helpful to be able to remove the shelf.
- The shelf I bought was unfinished, this isn’t a great idea since that causes a lot of friction between the surface and the mouse. Either get a glossy finished shelf or a mouse pad. Or sand paper and some wood polish might do.
A couple idea to improve the design:
- A cable hole through the middle of the top surface for USB cables from my monitor.
- A strap that somehow attaches the backside of the standing desk to the desk below, although I’m not really sure this is necessary.