Archive for November 30, 2015

Monday, November 30, 2015 [Tweets] [Favorites]

Optimizing Facebook for iOS Start Time

Natansh Verma:

Our instinct was that cold start was dominated by network and that the rest would be mostly response processing. This belief came from the assumption that we spent much less time on the client and that we managed to get the request out rather quickly. However, once we instrumented it, we found the data quite surprising. It presented a starkly different picture, with a significant portion of time spent before the feed request — on the order of a second. Also, the response processing time was very short. Hence, we refocused on optimizing the initialization phase.

[…]

As we stepped back, we figured that the objective for this phase was simply to send out the feed network request. But why was the feed request so late to get out? It was because many dependencies had been added to the initialization of the feed request over the years. However, they weren’t truly necessary — the bare minimum requirements for sending out the feed request were a valid authentication token and feed cursors (the location in News Feed). Hence, we whittled down the dependencies of the feed request, progressively moving it closer to the app’s launch. This allowed the rest of the app to initialize concurrently with the feed response.

[…]

We came up with a creative solution for this — UDP Priming. In essence, before we send out the feed request over TCP, we send an encrypted UDP packet to the server, containing the feed request. The purpose of doing this is to give a hint to the server to kick off fetching and caching of data much earlier. When the actual feed request arrives over TCP, the server can then simply construct the response from cached content and send it back. Enabling this technique allowed us to gain several hundred milliseconds more.

Swift init()

Krzysztof Zabłocki:

With Swift strong typing and immutability, there are rules that prevent you from accesing variables until an object is fully initialized.

I do not like having a function do more than one thing, so I like to split my initializers into multiple functions, this becomes problematic.

[…]

We can define private static functions and use that to setup our variables (and we can also put them into private class extension)[…]

Done With iCloud Photo Library

Stephen Hackett (comments):

Over the week of Thanksgiving, I decided to give it another try. I hadn’t really spent any time with Photos.app since OS X El Capitan, and I had heard a lot of good things from people I know about it.

I imported my photos and uploaded my 70GB photo library to iCloud. Everything went very smoothly, so I turned on iCloud Photo Library on my iPad.

Aaaaaand it all exploded.

[…]

I will probably keep my photos in Photos.app, but I won’t be uploading them to Apple’s service again. Photo management needs to be bulletproof, and iCloud has proved, yet again, to be far from it.

Update (2015-12-10): Christopher Sardegna:

Nearly all of the old photos I have in my iCloud Photo Library look like this. Great images, all gone. Destroyed.

Justin Searls:

My iCloud Photo Library is now so big that metadata/thumbnails can’t be loaded onto a 16GB iOS. Has to be disabled

Update (2016-12-13): Jonathan Wight:

People were asking me if using http://Photos.app for storing _all_ my photos was working for me?

Well today it ate them all. So no.

300 GB of photos no longer accessible in http://Photos.app. Fortunately I have many backups (not crazy!)

Favorite Terrible Programming Languages

Fogus:

Write about your favorite programming language honestly, but make it sound terrible.

Marcel Weiher:

Objective-C is a car crash of Smalltalk and C, combining the type-safety of the former with the memory-safety of the latter.

David Smith:

[Objective-C is] An attempt to graft an old children’s language onto the source of 97% of all security bugs and crashes

David Smith:

[Swift is] A forward-looking/past-looking scripting/applications/systems language with no source or link-time compatibility.

Joe Groff:

or working compiler

Benjamin Stiglitz:

[Forth has] No variables, no basic blocks, no syntax, no compiler, doesn’t understand strings.

David Smith:

“Our codebase was unmaintainable, so rather than refactor, we wrote a new language to rewrite it in” [Rust]

Damien Sorresso:

A language that language nerds can’t fathom the success of because its design was influenced by systems programmers.

I presume he’s referring to C.

Surprising Complexity Inside Apple’s Power Adapter

Ken Shirriff (comments):

This is a fantastic quote, but unfortunately it is entirely false. The switching power supply revolution happened before Apple came along, Apple’s design was similar to earlier power supplies[4] and other computers don’t use Rod Holt’s design. Nevertheless, Apple has extensively used switching power supplies and pushes the limits of charger design with their compact, stylish and advanced chargers.

[…]

The transformer safely transmits power between the primary and the secondary by using magnetic fields instead of a direct electrical connection. The coils of wire inside the transformer are triple-insulated for safety. Cheap counterfeit chargers usually skimp on the insulation, posing a safety hazard. The optoisolator uses an internal beam of light to transmit a feedback signal between the secondary and primary. The control chip on the primary side uses this feedback signal to adjust the switching frequency to keep the output voltage stable.

One unexpected component is a tiny circuit board with a microcontroller, which can be seen above. This 16-bit processor constantly monitors the charger’s voltage and current. It enables the output when the charger is connected to a Macbook, disables the output when the charger is disconnected, and shuts the charger off if there is a problem. This processor is a Texas Instruments MSP430 microcontroller, roughly as powerful as the processor inside the original Macintosh.