Cold Startup Optimization for Meituan Waimai iOS Client
Meituan Waimai improved its iOS client cold‑startup time by fixing existing bottlenecks, introducing a phased‑startup model with self‑registered modules, slimming code and +load methods, parallelizing UI work, and adding detailed runtime metrics, enabling continuous optimization despite rapid feature expansion.
This article shares Meituan Waimai iOS client’s experience in optimizing cold‑startup performance.
Background : The app has evolved into a platform with many business modules, increasing the work performed during cold start.
Cold‑startup definition : The authors define cold start as the period from user tapping the app icon until the main UI is visible, comprising three stages T1 (pre‑main), T2 (didFinishLaunching), and T3 (post‑launch UI rendering).
Current problems : Both accumulated (stock) and incremental performance issues exist, mainly due to a large number of startup items.
Governance ideas :
Resolve stock issues by optimizing existing bottlenecks.
Control incremental issues through a phased‑startup model and self‑registration of startup items.
Improve monitoring with detailed metrics.
Phased startup : Startup items are classified into early, middle, and late phases based on priority, allowing non‑critical items to be delayed.
Self‑registration : Startup functions are exported to a custom __DATA section (Kylin) and invoked at the appropriate phase.
__attribute__((used, section("__DATA","__kylin__"))) static const KLN_DATA __kylin__0 = (KLN_DATA){(KLN_DATA_HEADER){"Key", KLN_STRING, KLN_IS_ARRAY}, "Value"};Example registration:
KLN_FUNCTIONS_EXPORT(STAGE_KEY_A)() {
// startup code A
}In application:didFinishLaunchingWithOptions: the framework executes all functions registered for a given stage:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[KLNKylin sharedInstance] executeArrayForKey:STAGE_KEY_A];
return YES;
}Optimizing pre‑main work : Reduce dynamic libraries, Objective‑C classes, +load methods, C constructors, and C++ static objects.
Code slimming : Unused selectors are identified via Mach‑O sections; a script extracts them.
def referenced_selectors(path):
re_sel = re.compile("__TEXT:__objc_methname:(.+)")
# ... omitted for brevity
return refs+load optimization : Replace heavy +load implementations with custom initialization phases.
// Replace +load with a business init macro
WMAPP_BUSINESS_INIT_AFTER_HOMELOADING() {
// original +load code
}Profiling tools : Xcode Time Profiler and flame‑graph visualizations (Caesium) are used to locate hot spots.
Serial to parallel conversion : Splash screen is shown first, allowing UI construction to run in parallel; location caching and pre‑fetching of home data reduce serial dependencies.
Data monitoring : An internal Metrics system records cold‑startup timestamps from process creation (exec) to UI ready, providing percentile statistics for continuous improvement.
#import <sys/sysctl.h>
#import <mach/mach.h>
+ (BOOL)processInfoForPID:(int)pid procInfo:(struct kinfo_proc*)procInfo { … }
+ (NSTimeInterval)processStartTime { … }Conclusion : Continuous, systematic optimization—stock issue fixing, phased startup, self‑registration, and online monitoring—keeps Meituan Waimai’s iOS cold‑startup time within acceptable limits despite rapid feature growth.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Meituan Technology Team
Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
