Mobile Development 10 min read

How Youku Reduced App Size and Crashes When Embedding Alipay Mini‑Program SDK

This article explains how Youku tackled the large package size, thread‑explosion, and memory overhead introduced by integrating the Alipay mini‑program framework, using remote .so loading, layered dependency management, a unified thread pool, and lazy initialization to improve performance and stability.

Alibaba Terminal Technology
Alibaba Terminal Technology
Alibaba Terminal Technology
How Youku Reduced App Size and Crashes When Embedding Alipay Mini‑Program SDK

Integrating the Alipay mini‑program framework into the Youku app introduced several problems: the SDK package is large, the native .so files increase the app size, the mini‑program container spawns many threads causing higher crash rates, and the initialization slows startup and consumes memory.

The mini‑program SDK adds about 23 MB, with 7 MB of native .so files.

Thread count spikes after the mini‑program container starts, leading to crashes.

Loading the mini‑program engine delays app launch and raises memory usage.

To solve these issues, Youku applied a series of strategies:

Remote .so Loading

Youku extracts the .so files from the SDK, records their download URLs and MD5 checksums, uploads them to a server, and loads them on demand when the user opens a mini‑program.

Collect dependency relationships between .so files in advance.

Package the .so files separately, upload them, and store their remote URLs and MD5 values.

When a mini‑program is launched, download the required .so files to a designated directory.

Load the .so files sequentially according to the pre‑collected dependency order.

Dependency Analysis

The command used to list needed libraries is:

objdump -x *.so | grep -i needed | awk '{print $2}'

This reveals which libraries are required from the operating system and which come from other AAR packages; only the latter need to be recorded.

Layered Dependency Design

Dependencies are organized into three layers:

Layer 1: No dependencies on other AAR .so files, only OS or independent .so.

Layer 2: May depend on Layer 1 .so and OS .so.

Layer 3: May depend on Layer 1 and Layer 2 .so and OS .so.

Code Implementation for Loading Order

private static String[] LIB_NAMES = {
    // Layer 1 – no other .so dependencies
    "A1",
    "A2",
    "A3",
    "A4",

    // Layer 2 – depends on Layer 1
    "B1",
    "B2",
    "B3",

    // Layer 3 – depends on Layers 1 and 2
    "C1",
    "C2",

    // Further layers can be added as needed
};

public static void ensureAllSoLoaded() {
    try {
        for (String lib_name : LIB_NAMES) {
            Log.d(TAG, "lib_name:" + lib_name);
            System.loadLibrary(lib_name);
        }
    } catch (Throwable throwable) {
        Log.e(TAG, "loadLibrary lib_name exception:");
        throwable.printStackTrace();
    }
}

Thread‑Pool Injection

On devices with a thread‑count limit (e.g., some Huawei phones), Youku injects its unified thread pool into the mini‑program framework to avoid creating new threads for each task.

public class MyThreadPoolManager implements IThreadPoolManager {
    private static final int NCPU = Runtime.getRuntime().availableProcessors();
    private ThreadPoolExecutor mThreadPoolExecutor;

    @Override
    public ThreadPoolExecutor createExecutor(ScheduleType scheduleType) {
        if (mThreadPoolExecutor == null) {
            mThreadPoolExecutor = YKExecutorService.from(
                "miniappSdk",
                2 * NCPU + 1,
                2 * NCPU + 1,
                1000,
                TimeUnit.MILLISECONDS,
                new SynchronousQueue<Runnable>());
        }
        return mThreadPoolExecutor;
    }
}
// Alipay mini‑program SDK injects the thread pool
TinySdk.setThreadPoolManager(new MyThreadPoolManager());

After deployment, crash rates dropped by about 90 % across modules.

Lazy Loading

During early stages when traffic is low, the mini‑program framework is not initialized at app launch. Instead, a prompt informs the user about remote dependencies; upon consent, the required .so files are downloaded and the framework is initialized only when the user first opens a mini‑program, reducing startup time and memory usage.

Conclusion and Outlook

Remote .so loading reduced the app package by 7 MB, at the cost of a short initial download delay. Thread‑pool injection dramatically lowered crash occurrences. Future work includes moving the entire mini‑program framework to the cloud to eliminate any impact on app size, adding more generic JS APIs, and replacing lazy loading with idle‑time loading for an even smoother user experience.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

MiniProgramAndroidThreadPoolSOLazyLoadingAppOptimization
Alibaba Terminal Technology
Written by

Alibaba Terminal Technology

Official public account of Alibaba Terminal

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.