cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
6.58k stars 1.72k forks source link

构建后Web项目的引擎体积 #16712

Open a1076559139 opened 7 months ago

a1076559139 commented 7 months ago

Use Case

我主要的工作是开发Web端的营销类游戏,这类游戏对启动速度比较敏感。

Problem Description

3.8.0开始,引擎的体积因为spine的调整呈爆炸式的增长: System.import('cc')加载的_virtual_cc.js将近800K(gzip后)我这仅仅是2D游戏,而且已经裁剪了不需要的功能。 这还不算完,运行cc.game.run()后,又加载了将近700K(gzip后)的spine库文件,还有110K(gzip后)的internal文件(我没有用到shader等高级功能)。

在我们的性能统计中,90分位数据: System.import('cc') 耗时3秒左右 cc.game.run() 耗时5.5秒左右

Proposed Solution

No response

How it works

No response

Alternatives Considered

我觉得spine的体积可以减小,最好引擎可以支持Treeshake,或者将功能裁剪功能做的更好

Additional Information

No response

dumganhar commented 5 months ago

为了提升性能,我们将 spine 使用 c++ 实现,通过 emscripten 编译为 wasm/asmjs。因为要完整导出所有 spine 的接口,会产生比较多的 js <-> cpp(wasm) 的胶水代码,体积会比之前的大。

另外,如果是发布 web 平台,那么 3.8.3 之前的版本有个 bug,会同时加载 wasm 和 asmjs 的库文件。这个在 https://github.com/cocos/cocos-engine/pull/16679 中修复了。

a1076559139 commented 5 months ago

👌

allenlzg commented 5 months ago

2d游戏我都直接用 2.4版本的,小