Game Development 15 min read

Performance Optimization of Cocos Exported WeChat Mini‑Games: Strategies, Code Adjustments, and Testing Tools

This guide details practical performance‑optimization techniques for Cocos‑based WeChat mini‑games, covering scene and prefab optimizations, asset compression, code size reduction, garbage‑collection handling, mask usage, plugin assistance, code‑level improvements, and a suite of testing tools to measure and verify the gains.

IEG Growth Platform Technology Team
IEG Growth Platform Technology Team
IEG Growth Platform Technology Team
Performance Optimization of Cocos Exported WeChat Mini‑Games: Strategies, Code Adjustments, and Testing Tools

1. Background

Practice of performance optimization for a Cocos‑exported WeChat mini‑game, with before‑and‑after comparison screenshots.

2. General Performance‑Optimization Process

References:

Laya official performance‑optimization guide: https://ldc2.layabox.com/doc/?nav=zh-ts-2-2-1 Cocos performance‑optimization blog: https://new.qq.com/omn/20210413/20210413A04JEH00.html WeChat mini‑game performance guide: https://developers.weixin.qq.com/minigame/dev/guide/performance/perf-overview.html

These sources were consolidated into a set of project‑level optimization strategies.

1. Scene Optimization Strategies

Automatic resource release – before and after screenshots.

After optimization:

2. Atlas Batch Merging

2.1 Static Atlas

Use Cocos’ built‑in automatic atlas tool ( https://docs.cocos.com/creator/2.0/manual/zh/asset-workflow/auto-atlas.html ) and preview the generated atlas.

2.2 Dynamic Atlas (including text)

Before optimization screenshot:

After optimization screenshots:

For other scenes, apply similar methods; bitmap fonts are recommended over full font files.

3. Prefab Optimization

In the Prefab inspector, select the appropriate "Optimization Strategy" based on usage:

"Optimize multiple‑creation performance" generates JIT‑compiled instantiation code, reducing runtime instantiation cost but increasing load time.

"Optimize single‑creation performance" skips the JIT step, decreasing load time at the expense of slower instantiation, suitable for UI prefabs loaded only once.

Note: The WeChat mini‑game platform disables dynamic code loading (e.g., eval), so the optimization strategy option is ineffective on that platform.

4. Code Size Reduction

Remove unnecessary engine modules (e.g., physics) via Project Settings → Module Settings, then check the size of cocos2d‑js‑min.js .

5. Texture Compression

Reference: https://forum.cocos.org/t/topic/106919

Configure simple texture‑compression settings in Cocos Creator to compress images during packaging.

Batch‑compression script reference: https://www.chuyouxiang.com/archives/760

In practice, using pngyu for compression yields reliable results.

6. Reduce try catch Usage

Minimize try catch blocks because functions wrapped with them execute significantly slower.

7. Garbage Collection

Each Canvas or Image object in a mini‑game holds a client‑side texture that consumes memory. The texture is released only after the JavaScript object is collected. Call wx.triggerGC() to prompt JavaScriptCore GC, which may free those textures, though the exact timing depends on the engine.

Method documentation: https://developers.weixin.qq.com/minigame/dev/api/base/performance/wx.triggerGC.html

Typical usage scenarios:

Invoke at the start or end of each game round.

Combine with wx.onMemoryWarning to respond to memory warnings.

Call during scene switches to proactively free resources.

8. Reduce Mask Component Count

Mask components modify GL state before and after rendering, breaking draw‑call batching. Prefer bitmap processing or other techniques over masks for static effects like rounded icons.

9. Use Cocos Plugins

YH Multi UI plugin: https://forum.cocos.org/t/topic/134846

The plugin provides one‑click conversion and can significantly lower draw‑call count without manual optimization.

3. Code‑Level Optimization Process

The game "Ball Life Road" is a paddle‑ball brick‑breaker with buff‑induced multi‑ball splitting.

Key code‑level optimizations include:

1. Multi‑Ball Collision Detection

Cap the maximum number of balls (reduce threshold from 300 to 200, increase initial pool size accordingly).

Eliminate unnecessary ball‑to‑ball collision checks.

2. Home‑Page Level Data Display

Fetch level data remotely.

Paginate the display.

4. Performance Testing Tools

1. Cocos Browser Debug Info

Use draw‑call count as a primary indicator of optimization effectiveness.

2. WeChat Mini‑Game Real‑Device Debugging

Reference: https://developers.weixin.qq.com/minigame/dev/guide/performance/perf-action-memory-dev-profile.html

The built‑in DevTools (based on Chrome DevTools) allow live editing and rapid diagnosis.

Chrome DevTools: https://developer.chrome.com/docs/devtools/

2) Android Real‑Device Performance Tools

WeChat Android provides three memory‑analysis tools: performance panel, Heap Snapshot, and V8‑CPU‑Profile.

Address: https://developers.weixin.qq.com/minigame/dev/guide/performance/perf-action-device-monitor.html

3) PerfDog

A cross‑platform iOS/Android performance testing and analysis platform that works without rooting or jailbreaking.

Address: https://perfdog.qq.com/

3. WeChat Mini‑Game Cloud Testing (Recommended)

Cloud testing offers automated functional, performance, compatibility, and stability testing with comprehensive reports.

Supports standardized recording, playback, and test frameworks.

Integrates full‑stack testing capabilities.

Provides a large pool of real devices.

Delivers visual quality reports for quick issue location.

Service entry: https://developers.weixin.qq.com/minigame/dev/minigame-testtool/quick-start.html#%E8%BF%9B%E5%85%A5%E4%BA%91%E6%B5%8B%E8%AF%95

5. WeChat Mini‑Game Scoring Optimization

1. Startup

1) Data Pre‑fetch

Modify address: https://mp.weixin.qq.com/wxamp/devprofile/get_profile?token=1106658438⟨=zh_CN

Enabling pre‑fetch allows the mini‑program to pull required data before the user opens it, reducing load time.

Details: https://developers.weixin.qq.com/miniprogram/dev/framework/ability/pre-fetch.html
Mini‑games currently do not support this feature.

2) Mini‑Game Speed Test

Documentation: https://developers.weixin.qq.com/minigame/dev/guide/open-ability/performance-report.html

3) Engine Separation

When building, remove the compressed engine source files from the template to avoid MD5 mismatches.

The built‑in Cocos engine plugin has a bug that causes errors in scenes with automatic resource release; the issue has been reported for future fixing.

Bug report: https://developers.weixin.qq.com/community/develop/doc/0004800f2043288b96ddd20ec5b800?fromCreate=0

4) Code Dependencies

Delete unused code to shrink package size.

2. Network Performance

1) Periodic Data Updates

Enable background data fetching every 12 hours so the mini‑program can operate under weak or no network conditions.

Details: https://developers.weixin.qq.com/miniprogram/dev/framework/ability/background-fetch.html
frontendperformance optimizationGame developmentWeChat Mini GameAsset ManagementCocos
IEG Growth Platform Technology Team
Written by

IEG Growth Platform Technology Team

Official account of Tencent IEG Growth Platform Technology Team, showcasing cutting‑edge achievements across front‑end, back‑end, client, algorithm, testing and other domains.

0 followers
Reader feedback

How this landed with the community

login 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.