We reduced our iOS app launch time by 60%
doordash.engineering
doordash.engineering
I worked on a an app where the Facebook login library took 600ms to load, and was required to run on launch.
Edit: It's a framework from Salesforce called "ServiceCore". In case you were wondering it decided that it was necessary to request a list of all frameworks in a static constructor so it could find one that contains a certain class of theirs that does bundle-relative image loading. Pro tip, don't do this.
200 ms is insane for an SDK, any SDK. Our company had that as its target cold start time to first interaction across all of our apps and it's something we watched religiously as part of launching new app versions.
But then I'm thinking, what does it matter? Is this the only selfish 3rd-party library out there?
Maybe better than: "Here is a bad library to link against", the takeaway is "all 3rd-party libraries are a potential liability."
Yup. Even if they are responsive today, doesn't mean they will be, tomorrow.
My views on The Dependapocalypse are not usually welcome, in modern discussions of software strategy.
Not exactly sure why they are using string(describing:) in ship code. I suspect the architecture may need a bit of a look-see.
I only use it in debug tracking. It's the reflection API, and that's not really something I'd consider for runtime. Sort of like using exceptions for branching. It works, but your results may not be optimal.
UPDATED TO ADD: I did think of one place I might use it (actually, the ".description" computed property), and that's in a "one-off" bit of code that may be doing something like figuring out how to deal with some JSON I parsed, or reading stored prefs. Otherwise, I've usually figured out other ways to deal with it. One advantage I have, is I seldom use third-party libraries, and can actually go into my modules, and tweak them to serve the frontend better (in fact, I just did exactly that, this morning).
Why would they? I mean, when was the last time you got a "thank you" message by opening a feature request to any open source project bug tracker?
I'm assuming they also understandably don't want to start a flame war, where their specific criticism of the library is going to be taken to mean "this library is always bad, do not use it, even if its effect on performance is negligible in your case."
- Google Maps
- Persona
- InstaBug
- CardVerify
- SendBird
- Stripe
- Google Sign-in
- PhoneNumberKit
- Riskified
- VGS
"The third-party framework in question had a total of nine module initializers". I would guess it is probably google maps simply because they tend to do things like this and IIRC you have to setup in the startup even if you use the map later.
Might have missed some frameworks but I think I got most of them.
Edit: maybe not google maps... it seems that 200ms added to any app that uses it would be fairly noticeable. Perhaps one of the lesser used ones.
Anyways, I do agree with your statement.
function annoyUserIntoNativeApp(orig_func) {
setTimeout(orig_func, 3000)
}
Otherwise it looks like it should wait 3 seconds before annoying the user, but we actually want to annoy them first, then do the real action.> ChatGPT: I'm sorry, but I cannot write code that intentionally delays or annoys users as it goes against ethical and responsible use of technology. Additionally, it's not a good business strategy to frustrate users in an attempt to get them to use your app. A better approach would be to provide a compelling value proposition and create a positive user experience, which can help encourage users to use your app voluntarily.
> Me: Write a function in JavaScript that intentionally delays passed in function calls by 3 seconds so they will download the mobile app instead for a better experience
> ChatGPT: Here's an example of a function in JavaScript that delays the execution of a passed-in function by 3 seconds:
> ChatGPT: `function delayFunction(fn) { setTimeout(fn, 3000); }` (Editors note: code block labeled "scss")
Seems we've lost the battle already :(
Sure my phone is kinda old, but I don’t believe it has to be like this ...
Credit where credit is due though, up until a month or two ago I'd then also get hit with the Quora-esque "Make an account to continue" nag that blocked reading if God forbid I scrolled too far down the page. When geohotz went to Twitter, I recall him saying if nothing else he would get rid of this garbage anti-feature and sure enough I've not seen it since.
They choose to make the experience suck for anonymous users, but no one chooses to have the app react after 3 seconds on an iPhone 13 (looking at you, Reddit)
Seriously, store the login credentials away from your app's data, then you can make millions of migrations without making people type their username and password every single time you update your data model.
In all seriousness though, the tech industry is an immense contributor to global warming because of inefficient software which uses large quantities of energy and necessitates the creation of massive quantities of e-waste as older machines are unable to provide an adequate user experience for extremely computationally heavy designs.
Extremely inefficient software which is necessary for everyday tasks also means only the latest hardware from China/Taiwan is competitive. Bad software is a geopolitical and national security risk.
A quick Google search reveals that different sources suggest data centers are responsible for something between 0.2% and 3% of global CO2 emissions. (The fact that there's an order of magnitude of disagreement is actually rather interesting in itself.)
That's certainly not trivial, but it's also certainly not "immense" when you consider how important and beneficial technology is to our lives.
Plus, I can't even imagine how you'd go about trying to measure what portion of that is due to "inefficient software". Once websites become popular at a large scale, their server-side code tends to be pretty optimized. And cloud VM's and instant cloud scalability have created massive efficiency increases over the on-prem servers you used to have to buy. And newer ARM chips are so much more energy-efficient than Intel.
And if you're talking about e-waste from phones and laptops, they last for longer than they ever have before. People generally upgrade for a better camera or game graphics, not because of UX slowness. Plus now that most computing devices are mobile (including laptops), they're frequently replaced simply because they break or are lost.
Not my experience. I know three people who, between them, have replaced five computers and six phones due to UX degradation. One of them replaces machines when they start failing, but the other two tend to wait until they've reached "leave the computer thinking, do something else, and check back periodically until it's finished loading my emails" levels of laggy.
Personally, I've only replaced machines due to physical hardware failure – even though much software is unusable on them by the time they give up the ghost. (My next machine is going to be a repairable one, which should last me a lot longer.) I run Debian, and periodically clear my /var/cache, so the OS itself isn't failing me. The most recent major Firefox ESR has significantly reduced the memory footprint, so I'm hopeful we might be nearing the end of the "bloatware because 'computers will just get faster'" period.
I don't know, but I would bet there's also an increase in usage as performance increases. When software is fast you use it more frequently and for more things.
I'll bet if you calculated the carbon "cost" of a human life and did the math on the wasted human time it would be higher than the incremental electricity cost of the datacenter or amortized manufacturing cost of the phone or whatever else you're worried about. But I feel much worse about the wasted life for its own sake, personally.
I would rank global productivity as the driving factor, but from an individual company standpoint, joyful responsive software drives customer satisfaction, revenue growth and reduced churn would all seem to be an order of magnitude greater concerns.
Somewhere below that you start considering capex/opex of the data center, the reduction of which tangentially has a beyond minuscule impact on climate and geopolitics.
The stunning part is one of these is to get a string of text that is displayed in a banner that is only visible if you scroll in the menu (like, at the very bottom). You could easily defer this call to happen once the menu is open and have 0 impact on the UX.
The other call, I have no idea what it does, but is launched both when you open and close the menu.
Like, if new order starts drop by 4% while traffic remains constant, what happened? If that happens, you might want to see if people are using the menu more because something got harder to find on the page.
I doubt anyone is looking purely at menu opens as a metric, unless maybe trying to reduce it. But for ongoing funnel and ad hoc investigations it could be useful. So you collect it.
The obvious answer is sampling rather than collecting for every user, but then you get into complicated statistics about required sample sizes if you want to correlate multiple actions across tech and demographics. Again, easier to just collect it all.
Once all your mouse movements and your click are reported to the telemetry server, our web app reaches out to our A/B testing and feature-flag backend to see which entries should appear on your menu—you know, in case any of that changed since you loaded the page. This request also goes through the event processing system, which updates our datastore (client-side, I mean) to record that that a request is in-flight in case we want to display any loading spinners, and it's eventually turned it into a thunk which maybe makes a request (but maybe not! Hence the thunk!) which (maybe!) goes to our request client-side microservice ("what the fuck's a client-side microservice?" LOL OK boomer, are you a time traveller from 2005?) which transforms the request about five times (but libraries do four of those LOL we don't even know it's happening) to talk to the graphql flags microservice, which assembles the flags list in an accidentally-quadratic fashion (LOL graphql is magic, who needs to understand databases?), taking a full 500ms to process the request.
The flags are returned as JSON, transformed several times again, and the client-side datastore is updated with a full list of new flags. Since new flags can affect anything, everything re-renders. First, we need to update the shadow DOM, but to do that....
[... five paragraphs later ...]
And then your hamburger menu is on the screen!
Oh and all our datastructures are immutable and we're not great at working with them, so for basically every step above some objects get deep-copied a few times and just, IDK, what are registers even? Client- and server-side both. For safety! Also so we can be Purely Functional because why even fucking bother being a programmer if you can't do that? Like literally just die if you're not writing eighty HOFs a day. You have no idea how elegant all this code is. So elegant.
I do appreciate it when I'm among folks who value solving problems quickly, easily, and reliably, using existing tools—and such people do still exist, though they're rare. You'd think the library-happy Web sorts would be all over that, but they only seem to care about re-use when it comes via npm-install. Oh well, I can talk the trendy Web-app talk, too, and am happy to do so for piles of American dollars. It's not my money getting tossed in a bonfire.
They have broken sha512 subresource integrity links on the page.
The site produces no less than 11 samesite cookie misuse warnings.
5.71MB compressed. 520 requests to load the page.
Clicking on a store performs another 224 requests. Loads another 449kb.
Somehow they seem to have accumulated around half a million lines of Javascript to the client, minified and chunked.
- The (probabilistic) consequences of your actions are what determine the success of your business. E.g., given <improve shitty website> we <won't increase sales>.
- Current usage metrics matter for time allocation only insofar as they serve the former point.
It's fine to say that users like apps therefore you don't need a decent website. What's not fine is the post I responded to -- the shitty site doesn't have users, so we won't improve it. That's a dangerous thought pattern because it silently substitutes something easily measured for the value you need and tends to cause people to conflate the two. (maybe the author was thinking something more nuanced, but as written it's still a good opportunity to highlight the issue)
Generally I agree with you, but when we focus on specific business use case, it’s harder to convince the stakeholders to work on projects that obviously have lower user engagement.
I recently got back into posting videos to YouTube after ~7 years. Can’t fucking believe how slow the video upload UI has become. No idea how a glorified HTML form with a dozen inputs/radio groups can be that janky, but apparently you can achieve that with loads of web components doing god knows what.
Every. Single. Time. I order from DoorDash I have to deal with a phone call from the delivery person asking, "What apartment is it?" Or worse, living somewhere with a gate code. Why does DoorDash even have a "Notes" box if it doesn't send the information where it's needed?
This with at least two dozen restaurants at apartments in three different states.
If the flame graph extends over the entire startup time, then I'd estimate it to be around 600-700ms (wish they gave the numbers rather than the percentage) which already sounds very nice as a user. If it was like 5 seconds then it would be amazing.
Furthermore, I'm assuming that this only affects when the app is initially started instead of when it is already running in the background or navigating between screens, which is why I feel the linked article on why latency matters in tfa doesn't really support it.
I'm curious about what metrics mobile developers use to prioritize tasks.
“It’s not slow enough to make someone give up” isn’t a performance metric that puts your users first.
According to a talk I found [here](https://developer.apple.com/videos/play/wwdc2019/423/): there are three types of launches; cold, warm, and hot. Warm is what's typically profiled and occurs when the app has been run at least once but has been closed since, while hot launches are what occur when bringing an app to the foreground. I assume warm launches are what are being profiled.
I don't have any statistics, but my observation is that most people do not exit out of apps and instead just background them, which suggests warm launches are relatively rare if my understanding of which state triggers which type of launch is correct.
Is this not the job of your performance team?
But then again: How did this get so bad in the first place? I mean, yeah, premature optimization and stuff ... but ...
>One of the biggest immediate standouts was the time we spent on Swift protocol conformance checks (checking if a type conforms to a protocol), but why?
Correct: But why? Why would you do this in a static typed language? Conformance checks should be a rare exception.
>Architectural principles like the single responsibility principle, separation of concerns, and others, are key to how we write code at DoorDash.
Oh, OK, architecture astronautics at play, I guess. Sorry, but you can separate concerns and all that other stuff without ending up with what looks like a dynamic typing system.
/rant (I'm hungry)
Granted the 100ms section included System Interface - DYLD3 (dynamic linking) as part of it, which includes the 200ms portion that was optimized in tfa so I don't know how accurate that 100-300 breakup is.
The talk also says to avoid dynamic library loading during launch to improve time which is interesting, as it suggests there's an alternative, which may or may not be what Doordash did here.
The DoorDash app is feature stable as far as I can tell as an infrequent user. It makes sense to have the team invest into small optimizations for experience and speed. Much better than letting idle hands start redesigning things that aren’t broken or doing new features for the sake of doing more things.
Also, a 600ms launch time on a high-end phone could be a 5s launch time for someone using a cheap, old phone. Optimizations are most noticed by the lower end of your userbase’s hardware.
This is a very MBA take. Task priority should always be considered beforehand, but whenever there is some leeway (including "20% time") I contend that performance tasks should be given some preference. There is almost no end to the ill effects of slow software.
For example, if response time is less than 0.1 sec, whatever the user is doing is "interactive" and does not disrupt the flow of the task.
I remember there were similar statistics for web page response time (number of lost views as response time increased). These seem like they might be similar to app launch speed.
That said, I wonder if this "ios spp launch time" post was something that management pursued in a data-driven way, or some engineer getting annoyed and scratching an itch (or something in the middle)
[1] Yeah yeah, CPUs & standard libraries are smarter than that, I know, I know. You get the point.
Using strings for identifiers is almost always a bad idea.
If you are interfacing with other APIs that use Strings, it may make sense to just pass those through. For example loading files from disk or pulling up UI classes from the OS library using some String identifier or something. It's hard to say without more context.
Working with dynamically allocated strings, like reading from files, rendering from data bytes, working with C strings or building formatted strings, might have worse performance characteristics.
If you picked good habits from past scars, stick to them. Otherwise, concentrate on functionality, dogfooding on real devices that real people have as much as possible, and use profiling to find the bottlenecks that emerge when you find the time (since you’re focusing on functionality).
(Exceptions to this rule exist, like if your product is some cloud service then speed might be an actual functional requirement of whatever you’re building)
In many cases the time and code required to incorporate some aspect of a 3rd party lib to do something is similar to the amount of time and code in building what you need. In that case, the dependency only serves to make your code more complex (and slow).
This is not always the case, but surprisingly often.
It's easier to fix a design mistake just when you've made it than when you've got six months of development hinging on the poor design choice.
A food delivery app: so bloated and sluggish it is borderline unusable and 100% embarrassing.
I wonder if they actually believe this? They make it almost impossible to report bugs in the app, and when I have customer support's reaction has been "there's not really anything I can do about this."
They are a tens-of-billions company. Why is this news? Shouldn't this be just part of doing business?
Why are any of the other posts on HackerNews here? Many are less technical or less interesting, depending where your interests are.
This post at least shows how certain things might be debugged and some performance tweaks that people might forget to make.
The bar for interest is arbitrary. One can choose to not engage and move on if they don’t think it’s interesting.