

Making News Feed nearly 50% faster on iOS - dsr12
https://code.facebook.com/posts/340384146140520/making-news-feed-nearly-50-faster-on-ios/

======
Cthulhu_
I really hope Apple will come up with a modern alternative to Core Data; it's
neat and all, but it just doesn't feel like it's a good match for most
situations.

In my own anecdote, we had to show a list of autocompletion items - simple
enough. Read XML, write a few hundred entries to a Core Data storage - and
this list was relatively static, updated only once a week.

A week after release, we got crash reports - the XML read and store in
CoreData was still running while people were already accessing the
autocomplete list. It took (IIRC) 10 - 15 seconds to run (on an old iPhone
3GS), which was far too long from any standpoint.

So we just tossed CoreData, stored the list as a simple in-memory list, and
made the autocomplete match search a very naive iteration-based search. Ten
times faster, if not more.

TL;DR I would avoid CoreData, unless it's relatively static and non-time-
critical data. And even then I'd look for alternatives first.

~~~
smackfu
CoreData is really meant for storing the entries that back your table view.
Trying to use it as a universal data model seems unintended.

~~~
gress
You might be right that it's best for that, but CoreData pre-dates table views
by many years and has always been sold by Apple as a general store for object
graphs.

~~~
mikeash
Pre-dates table views? NSTableView dates to the 1990s. Core Data was
introduced in 2005.

~~~
dozenal
Core Data was based on the Enterprise Object Framework from NeXT.

~~~
mikeash
Only loosely. And I don't believe EOF predates table views either.

~~~
dozenal
Okay, but I"m still not buying that Core Data had no design goals beyond
backing store for table views.

~~~
mikeash
Oh yes, I certainly wouldn't try to argue with _that_. In classic Apple
fashion, they seem to try to sell it as the solution for all things data
storage.

------
coldcode
I could have told them that. In my previous job I dealt with large JSON data
as well but did not use Core Data but went with an immutable data layer as
well. If you had to modify anything you had to make a new one. Core Data is
fine for things that have to be modifiable and uploaded but if your
requirement is mostly read only it's silly overhead.

~~~
objclxt
I am pretty confident this is how Twitter manage data on their iOS app as
well, and I'm also pretty sure they went through a similar "let's use a
database/ORM, actually let's just write it to disk" process.

------
Moto7451
The three principles they listed for their model have served me well in apps
I've written, especially the first (immutability). Most of the Apps I write
rely on some kind of server data so it works really well. I'm writing a recipe
book app as a learning project and I'm experimenting with just saving JSON to
the App's document folder as a persistence layer.

------
gdubs
Interesting article, but worth pointing out that core data is not an ORM, but
an object graph with facilities for persistence.

~~~
adamjernst
You're right about this. My terminology was incorrect.

------
ynotgiant
[https://www.youtube.com/watch?v=XhXC4SKOGfQ](https://www.youtube.com/watch?v=XhXC4SKOGfQ)
is from the @scale conference last month that goes into more technical details
about the architecture. Presented by the same person as the author of the
article.

------
gsteph22
We hit similar problems with Core Data for
[http://clothapp.com](http://clothapp.com) and ended up migrating to Realm
([http://realm.io](http://realm.io)) last month. Been pretty happy with it so
far.

------
ExoticObjects
Is it me or does this article end right when some actual implementation
details would have been interesting to see?

~~~
jfernandez
Yeah I would've loved a little more detail on how they architected the move to
NSCoding / serialization straight to disk. There's a lot more ways to do this
wrong than right from how open-ended a 'schema' like that is. Any
speculations?

~~~
aaronbrethorst
A while back, I came to the same conclusion as Facebook's iOS engineers for
some apps that I work on. I based the model layer of the apps on Github's
Mantle: [https://github.com/Mantle/Mantle](https://github.com/Mantle/Mantle)

Facebook's implementation probably ended up looking somewhat similar.

------
sproutworks
It's pretty interesting to read about this stuff, I'm glad they're making
progress. I hope they also work on the app accumulating data that never seems
to get purged, or at least add a button to manually purge data.

------
bjornlouser
What bothers me about this industry is that if you were to interview for an
iOS position at a place like FB and suggest a KISS type solution, say using
PONSOs for the data model, you would immediately be shown the door.

~~~
forrestthewoods
Since I had to look it up and I doubt I'm alone:

KISS - Keep it simple, stupid

PONSO - Plain ol NSObject

------
joelrunyon
How long until they put messaging back within the fb app?

------
bsbechtel
What's up with all the Facebook posts ending up at the top of HN lately?

~~~
tannerc
Lots of hacking efforts = greater likelihood of those efforts capturing
attention and showing up in places like the top of HN.

