Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(wechat): performance polyfill delegates to wx.getPerformance()

yhh4e1e0d508966
diff --git a/sdk/src/platform/wechat/index.ts b/sdk/src/platform/wechat/index.ts
index 320079a75..7baa0c79a 100644
--- a/sdk/src/platform/wechat/index.ts
+++ b/sdk/src/platform/wechat/index.ts
@@ -263,14 +263,18 @@ export function initWeChatPlatform(): void {
function polyfillPerformance(): void {
const g = globalThis as any;
- if (typeof g.performance === 'undefined') {
- const start = Date.now();
- g.performance = {
- now(): number {
- return Date.now() - start;
- }
- };
+ if (typeof g.performance !== 'undefined') return;
+ // Prefer WeChat's own high-res clock: its framework SDK reads
+ // globalThis.performance and needs the full object (getSystemNanoTime etc.),
+ // not a bare { now } — a stub makes getFileSystemManager and friends throw.
+ const wxAny = wx as unknown as { getPerformance?: () => { now?: () => number } };
+ const wxPerf = typeof wxAny.getPerformance === 'function' ? wxAny.getPerformance() : null;
+ if (wxPerf && typeof wxPerf.now === 'function') {
+ g.performance = wxPerf;
+ return;
}
+ const start = Date.now();
+ g.performance = { now: (): number => Date.now() - start };
}
function polyfillTextEncoder(): void {