Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Rewriting the Messenger codebase for a faster, smaller, simpler messaging app (2020) (fb.com)
52 points by luu on May 12, 2023 | hide | past | favorite | 57 comments


Is it me, or are they implicitly saying that they're ditching React Native in favour of native code? That's a pretty big deal if that's the case.


They didn’t use react native for messenger previously.


They’ve ditched react native for quite some time now


And I don't think this is a knock against it. React Native is mainly an effort-multiplier, and Facebook has plenty of resources to do 2x the work (or 1.5x or whatever it is in practice)


Do they still after all the layoffs though?

And it's not just an effort multiplier, it also provides a unified codebase on both platforms which helps to provide a more consistent UX and less bugs.


“Consistent” UX is often one of the downsides of cross platform frameworks. Android and iOS have distinct UX details that users expect in their apps.


Yes but React Native uses native elements. It doesn't fake them like Flutter. It just provides a unified way to address them.


This is a problem even with desktop apps. Look at the print dialog abomination that Firefox unleashed on us.


Chrome did it first, and (at least on Windows) the system print dialog sucks anyway.


Sure, and the single biggest weakness over at Mozilla is that they're more focused on building a better Chrome (a.k.a. following the leader) instead of innovating or fixing bugs. That's why we've lost useful tools like the 3D DOM rendering in favor of a fucking chat client in Thunderbird. Or why if your system is lagged enough you can hit Cmd+T, start typing a URL, hit return, and have Firefox load the new URL in the old tab… but at least we have that awful search instead of separate, proper, URL and search bars. It's why we get limited-time-only!!! paid themes while all extensions get disabled because someone forgot to deal with an expired certificate.

Mozilla, and by extension the Firefox crew, lost sight of their core competencies a long time ago. Every dumbass design decision the Chrome folks make, Mozilla will emulate a few years later.


Definitely agree on some of this stuff. The themes situation sounded pretty delusional the whole time. And there were many more decisions like that.

However, what is this about separate search and url boxes? I have that, still. You don't have to have just the single box. Still, the main url box still behaves as a search either way. Is that what you mean?


I also think Firefox had lost its way, but not because of these things.


IIRC Thunderbird is a separate project now, not part of Mozilla, no?


Well they went corporate (MZLA Technologies) but they are still under the mozilla foundation.


React was the last new curve of single code base.

Things like Flutter are the new ones that have been able to learn from and improve on it.


I generally prefer react native apps (note that this is not the same as react which is more of a web framework) over Flutter. Because Flutter fakes native UI elements instead of just calling them.


Typo, I meant react native and not react in my comment.

React native is pretty heavy. Works nice and happy for those who enjoy it.


The desktop messenger apps are still react native. The mobile apps were always native (ObjC and C++ on iOS, C++ and Java on Android). The mentioned project was mostly to rewrite the core of messenger in C to further reduce overhead and code size compared to those other mentioned languages.


Can anyone shed light on where the complexity is coming from? Even 360kloc for a chat client seems excessive - its original size, 1.7Mloc, is hard to accept. How does it break down - e.g. 120kloc UI, 120kloc networking/data, and 120kloc other?

(For comparison I dl'd https://github.com/signalapp/Signal-iOS and ran cloc. It's about 400kloc of Swift, so I guess it's in the ballpark. I just wouldn't have guessed it was so big, and I'd like to know why.)


Just conjecture here since I have not ever done work in the messenger space: Perhaps it’s like Uber in that all of the complexity comes from localization features?

Edit: I saw another post further down that hypothesized that all of the complexity was with integrations outside of barebones messaging like photos, calls, other Facebook products etc. which seems plausible as well


Because you don't make money deleting code. People at tech giants don't love their employers like they are their mother or something. They don't do things that don't get them rewarded. Implementing new features does.

And so engineers implement new features and write more code and release the features and get rewarded for doing so. Once the feature is done, if it's easy to delete it they will. If not, and it never is, they'll leave it around and move on to something else.

When you have 3 billion users if you make the company 1/100th of a penny per user per year you pay for yourself. That's like increasing the value of the average user by 1/200,000. So your feature doesn't even have to be that good. It just has to be minimally better than what it's replacing. Restyle a button to be more appealing in the peripheral vision of users and that probably breaches that threshold.

Reality is that it isn't quite this easy (fewer users are that valuable, most don't use it daily, etc). But it gets the point across. You work there to make more money and deleting some feature that is probably referenced by some other dead code somewhere else isn't profitable work for anybody.


I don't think it's the feature count that's in question; it's the ratio of feature count to lines of code that seems abnormal.


I actually don't think it's a ton. Go count the lines of code of one of your small projects. I have something I spun up in the evenings over a few days and it's 2000 lines. It feels like nothing.

Tech giants have thousands of engineers working on these projects for many years and delete and rewrite features on a regular cadence. The fact that Messenger is only ~500 times bigger than my project is kinda weird to me. Mine has 1 user, it has 3 billion.


Well that's a grim tragedy of the commons. Not that I doubt you at all, but how depressing!


Why is it depressing? Does some collection of people on earth suffer from tech giant apps having too many lines of code? It very effectively shovels money from these soulless companies into the pockets of the employees. No living entity is suffering, just the company from it's own bloat.

I find it to be quite a beautiful result. Developers get to develop and not focus on maintenance. The lack of local maintenance creates repository wide maintenance jobs that are also interesting in their own right.

It is tragedy of the commons. But really the only one who deals with the tragedy is the corporate entity.


Companies don't suffer. That is reserved for the living.

The depressing part is the large amount of waste here. Wasted time, wasted opportunity, wasted money. Wasted lives. What you're doing here is known as the broken window fallacy.

The same developers could be developing meaningful things. They could be learning, like adults do, how to clean up after themselves, and so lead richer lives. The people forced into being code janitors could spend their time making things that actually get used. Or everybody could just do less work and go home early, doing things they care about.

And speaking of use, let's note that the waste impacts the users and the world. The users could be getting better software. More useful features. Fewer bugs. New products, new ideas. They could also avoid a lot of the chaos that comes when a company dies of pernicious waste. For example, note that the original browser company, Netscape, failed due to poor code maintenance, letting IE take over. What might have happened if they had done better?


My bet is on "object-oriented obfuscation" and bloat caused by "modern" coding styles. Looking through the Signal source you linked to, I see tons of the former. There is an absolutely insane amount of boilerplate-looking code in here, for example: https://github.com/signalapp/Signal-iOS/tree/main/Signal/src...

I don't know Swift or the iOS UI API, but a lot of that code seems to be manually creating and positioning UI elements and otherwise implementing UI functionality that I'd expect the OS to handle. It's a lot of code that should really be data (arrays, structures).

To offer a huge contrast, a long time ago I wrote an MSNP chat client in pure Win32, and it was around 2kloc. The binary was 24KB. Of course it only supported contacts, presence, and text messaging, but I still can't see features like audio/video or the crypto that Signal has needing 100x more, especially if they use OS functionality for much of them.


One guess: abstracting abstraction enough times can accomplish pretty much any Mloc.


Article is from 2020.


Updated, thanks


Just curious, how did you update a submission you didn't submit?

Edit: @flockonus (now deleted, why'd you do that, my new HN friend?!)

If by "karma == moving maintains" you mean emailing hn@ycbombinator.com like the rest of us.. then ok ;)


Some users can add dates to submissions that lack them.


Messenger on Android is genuinely one of the buggiest pieces of software I have ever used. It astounds me that people will take technical advice and use software libraries developed by this company that delivers such poor quality software.

Just a few of the issues off the top of my head. Most of these have been ongoing for several months and some for several years.

* Type something into the input box, quick-switch to another app, then switch back to messenger. Your half-finished message is now gone. But if you kill messenger completely then bring it back, your message is back - even if you have sent and received dozens of messages in the interim.

* The sticker selector has been completely broken for at least 3 years. It shows the grey smiley face placeholder image for every sticker pack apart from your bitmoji rip-off pack. This bug has been around long enough that I have verified it happens on 3 different phones from different manufactures (because I have upgraded twice in the time this bug has existed).

* The recently used emoji category may as well be using a random number generator to select what goes in there.

* The share menu from other apps sometimes shows Messenger twice. This doesn't happen for any other apps for me.

* Custom notification sounds on a chat will randomly revert back to the hideous default sound.

* Images I post will display properly until one other person sends a message to the chat, then will turn white and not come back unless I hard-stop the app and bring it back. It's not clear if this is occurring for other people in the chat, but I've only seen it happen to my own images and not others'.

* Quite often someone will post a picture to the chat and instead of a picture I will see them post the message "XXXX posted a photo". The only way to see the photo is to hard-kill the app and bring it back.

There are so many more. Terrible software.


The article is about the iOS version of Messenger.


Yes you can see I started my comment with the words "Messenger on Android". Hope that clears things up.


commenting about Messenger on Android when the article is about code-based iOS optimizations is not really relevant.


My comment was about the quality of the output from Facebook engineers.


The Android version is pure rubbish.

My favourite thing is perhaps how they auto convert everything to emoji even on my (S21U) mobile where my keyboard has direct emoji input.

I like my text based smileys dammit - please let me keep them! :-)


Would it not be possible to write a good messenger app in say 10,000 lines of code? What are the other hundreds of thousands of lines doing?


Messenger does a ton of things. It does video calls, voice calls, text messages... you can send money, send gifs, send videos... you can even view Instagram Stories for some fucking reason.


Pedantically, Instagram stories and Facebook stories are two separate things.


I’d be shocked if they don’t have 10k loc devoted to the status indicator alone. It’s cross user-facing service, cross platform, and notoriously unreliable enough to be a convenient excuse for social inaction (not that I’d know anything about that /s).


That is probably mostly handled by a backend service. Client code should be minimal


Analytics perhaps, then handling “Login with Facebook” buttons in other apps.


implementing error handling and features


> In the end, we reduced core Messenger code by 84 percent, from more than 1.7M lines to 360,000.

iOS only.


This is the coolest thing to me:

“We accomplished this by using the native OS wherever possible, reusing the UI with dynamic templates powered by SQLite, using SQLite as a universal system, and building a server broker to operate as a universal gateway between Messenger and its server features.”


This was a clusterfuck. When David Marcus failed upwards they decided to throw out the overcrammed feature experiments that had turned the app into Word 2000, a deluge of features with 2-8% user base.

But they never informed any of the dozens of other teams in the company they had courted for 5 years … gaming, payments, bots, etc and who had been building on top of it and brought partners.

Just overnight suddenly they went ‘fuck you and your customers, we need to compete with iMessage in the US, we deprecate everything and your partners can eat it’

Of course it failed and the cost was massive - partner trust was destroyed, game developers ruined, people left without access to bot based financial services, etc.


What’s the context here? As someone who doesn’t know anything about Facebook or messenger I have difficulties understanding what happened. Are you saying that this rewrite was a clusterfuck, or that the previous implementation was one?


I can’t remember if this is the exact library LightSpeed uses, but this CG/SQL library that Meta made makes it easier to write complex SQL queries for SQLite:

https://cgsql.dev/


Yes, it's the same one.


Is it still using Objective-C? Is there still a job market for Objective-C developers or only in big companies to maintain legacy apps?


Messenger is primarily a C codebase.


i wonder how vk does everything faster than facebook. their website and apps feel much faster and snappier.


Must have been embarrassed after that recent reverse engineering messenger blog post / tour de force marathon.


Seems like a waste of time machine, considering this article was written before the blog post.


Facebook doesn’t really care about reverse engineering in my experience.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: