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.77k stars 1.76k forks source link

CC3 Engine Code double size from CC2 #10354

Open Ronsku opened 2 years ago

Ronsku commented 2 years ago

In CC3 the cc.js engine file seems to be quite a bit larger than in CC2. It's still huge after disabling all the features I don't need. Are you looking into making it smaller or isn't it possible?

CC3 (2200 KB) image

CC2 (1011 KB, Over 100% smaller!) image

And this one from CC3 is with almost every feature turned off: image

I'm guessing there are something from 3D that is not cleaned up in the engine, even though you create a fully 2D game? This has a big effect on total bundle size of games.

minggo commented 2 years ago

@Ronsku yep, we are still trying do more effort on it. Can i know where will you publish your games?

Ronsku commented 2 years ago

Thanks @minggo, great to hear! I only publish for web-mobile platform, let me know if I can help testing in any way.

minggo commented 2 years ago

Thanks @Ronsku , i will ask your help if needed. Can i know more about the web-mobile platform? What's the limitation of the platform, for example, size limitation. And how can you earn money from it?

Ronsku commented 2 years ago

@minggo, No limitations really, just like any website or software you want it to be loading as fast as possible to your users. Doubling the size of the engine causes bigger loading times and a worse user-experience. Earnings comes from user satisfaction and from the same logic as loading a webpage. If the webpage you are going to is loading for too long you might leave it and the company would lose a potential customer.

I think loading times are always very important for a good UX. You want to play, not watch a loading screen.

minggo commented 2 years ago

@Ronsku thanks for the information. How long it takes based on your testing? And what's the loading time is acceptable?

Ronsku commented 2 years ago

@Ronsku thanks for the information. How long it takes based on your testing? And what's the loading time is acceptable?

That's a very difficult question to answer, since it is all based on server and user connection and also user's device that needs to run the code, launch the Web Canvas etc. The smaller the better without of course sacrificing features. This is why the "Feature Cropping" is a thing in Cocos Creator, to make the final bundle as small as possible while maintaining the features you've selected for your game. This way you wouldn't for example need to download all 3D features in a 2D game or DragonBones, unless you use it. Just as examples.

Problem in this case is that the CC3 final built code with most features cropped out is still double the side of the final build of a CC2 game.

Thank you @pandamicro for picking this up. Highly appreciated!

Ronsku commented 2 years ago

@pandamicro and @minggo I have confirmed that CC package size has gone up again in CC 3.5 slightly image from CC2: 1011Kb CC 3.4: 2,200kb CC 3.5: 2,247kb This is also with removing Marionette system from previous test image Almost everything removed and package still big.

I'm not sure what is making it so massive, but it hurts loading times a lot.

SantyWang commented 2 years ago

Yes, we have identified some optimization points, such as eliminating built-in effects and optimizing the decorators, and in version 3.6, we will optimize these part

Ronsku commented 2 years ago

Yes, we have identified some optimization points, such as eliminating built-in effects and optimizing the decorators, and in version 3.6, we will optimize these part

Amazing, can't wait! I will be a very big boost to the game loading :)

smitpatel88 commented 2 years ago

@holycanvas Does this help in native env as well?

Ronsku commented 2 years ago

@holycanvas I really hope this ticket will be taken seriously, because it is actually causing a lot of problems for me currently.

Having over 2x size on cc.js doesn't only cause 2x loading downloading time, but the worst part is that especially on slower devices parsing of huge JavaScript files is really costly.

I have huge difference between loading CC2 and CC3 games. I was even struggling a bit in CC2 to get good loading times. Now in CC3 it just takes way too long with this massive 2.2Mb chunk of JavaScript. Of course I run it through GZIP, but it's still double the size from CC2.

Can you help me understand what is the main reason behind the size? Are there any way to manually clean up features not used?

Ronsku commented 2 years ago

Yes, we have identified some optimization points, such as eliminating built-in effects and optimizing the decorators, and in version 3.6, we will optimize these part

How about "Feature Cropping"? It doesn't seem to affect the bundle size if you check out most of the packages form the feature cropping in project settings.

For example in 2D games, I'm just guessing that the whole 3D library is packaged with it, even though it is not selected in the feature cropping.

Ronsku commented 2 years ago

Some Google Lighthouse stats, on a game with most features removed ๐Ÿ˜ฌ

Non-GZIP image image image

GZIP:ed image image image

Ronsku commented 2 years ago

Same on CC 2 Gzip:ed, not great, but much better: image image image

shrinktofit commented 2 years ago

@Ronsku Have you tried the build setting "Erase module structure(experimental)"? That option will flattern import chain.

Ronsku commented 2 years ago

@shrinktofit No I had not tried that one before. I tried it now with an empty project. Here are the results: Feature Cropping: image

Build Settings WITHOUT "Erase module structure(experimental)" image image

Build Settings WITH "Erase module structure(experimental)" image image

Size of the Engine code is exactly the same ๐Ÿ˜ž

shrinktofit commented 2 years ago

@Ronsku Well this option is dedicated to project scripts, not engine :)

Ronsku commented 2 years ago

@shrinktofit I see, but didn't help with loading speed for me at least. Engine size is the issue

pandamicro commented 2 years ago

In v3.6, we will remove effects.js from the engine to achieve two goals

  1. Reduce engine package size by 20% - 30%
  2. Improve engine initialize speed by only loading necessary shaders to GPU

This is also described in https://github.com/cocos/cocos-engine/issues/10529, so we will complete the last in v3.6, and I'm moving this issue to v3.7 so that we can keep tracking further optimizations

@holycanvas How is the progression of this task ?

Ronsku commented 2 years ago

@holycanvas How is the progression of this task ?

@holycanvas Is this ready for 3.6 already. Am I able to see fetch it as a custom engine already or is this a build in editor feature somehow?

SantyWang commented 2 years ago

@holycanvas Is this ready for 3.6 already

@Ronsku Yes, In 3.6, all builtin effects had been removed from engine

Ronsku commented 2 years ago

in 3.6.0 beta we've gone down from 2.2mb to 1.7mb in size of the built engine (77.3% of previous). When GZIP:ed it went down from 743Kb to 603Kb (81.2% of previous)

Compared to CC2 the difference is still big: CC2: Gzip:ed: 380Kb CC3: Gzip:ed: 603Kb (59% bigger)

SantyWang commented 2 years ago

Thanks for your testing. In v3.6, we have optimized some effect. and In v3.7, We will optimize the module and decorator and so on.

Ronsku commented 1 year ago

Update from CC 3.7.0 I just ran a very basic 2D game build with no 3D features in the feature cropping and only a few 2D things picked. The engine size is even bigger than before 2330 KB compared to CC2 which currently run around 990 KB

CC3: image

CC2: image

Ronsku commented 1 year ago

Update on CC 3.7.0

By Removing

We come down to 1796 KB, but that's still Double the size of CC2 and loading is not only download size, but also weaker devices Evaluation and CPU time going through all of that code.

image image

Ronsku commented 1 year ago

@PPpro @holycanvas @pandamicro "PPpro removed this from the V3.7 milestone on Dec 5, 2022"

Are there any plans to bring this back? This and scene swapping performance https://github.com/cocos/cocos-engine/issues/11503, are the main reasons I have to stick with CC2 instead of CC3.

I need to be able to create 2D games that loads fast and efficiently. CC2 is already much slower and bigger than than for example PixiJS, but still in an acceptable range. While CC3 becomes so slow and heavy that it's not an option anymore :(.

I and a lot of other people really wants to swap to CC3 to get all the other benefits from it, but we're unable due to this.

minggo commented 1 year ago

@Ronsku we are improving modularization these days. Then developers can use features they want. It will be released in v3.8, which is planned to be released in June.

Ronsku commented 1 year ago

3.7.2 Update, engine size has remained close to 2mb (2x size of CC2) image Result of build: image

PPpro commented 1 year ago

Sorry, we adjusted this issue plan to milestrone 3.9

Ronsku commented 1 year ago

Sorry, we adjusted this issue plan to milestrone 3.9

Okay, thanks for the update! Hoping so much for a great size reduction and speed of initial load, so that I can swap from CC2 to CC3 before it becomes CC4.

Thanks, let me know if I can help in any way!

hubluesky commented 1 year ago

้บป็ƒฆไธ€่ตท็œ‹็œ‹3.xๅ„ไธช็‰ˆๆœฌไน‹ๅŽ็š„ๅŒ…ไฝ“ๅขžๅŠ ๏ผŒๅบ”่ฏฅๆ˜ฏ็›ธๅŒ็š„้—ฎ้ข˜ใ€‚ https://forum.cocos.org/t/topic/145082

Ronsku commented 1 year ago

้บป็ƒฆไธ€่ตท็œ‹็œ‹3.xๅ„ไธช็‰ˆๆœฌไน‹ๅŽ็š„ๅŒ…ไฝ“ๅขžๅŠ ๏ผŒๅบ”่ฏฅๆ˜ฏ็›ธๅŒ็š„้—ฎ้ข˜ใ€‚ https://forum.cocos.org/t/topic/145082

Thanks for posting this on the forums as well! Any attention to this will help๐Ÿ˜Š. Engine size and initial load times are so important. I understand that 3D games requires a bigger engine bundle, but there are a lot of people that still want to make 2D games. I first liked the idea of bringing Cocos 3D into Cocos Creator, which back in CC2 was only for 2D games. But I could have never guessed that we would ruin 2D game creation by having bundle size and load times 2x as long for the same thing.

I'm just hoping that we could get the latest Cocos Creator versions bundle size and loading times to be as good or better as it was to create 2D games in CC2 many years back.

I'm still forced to use 2.4.11.

jareguo commented 1 year ago

Re: https://forum.cocos.org/t/topic/149894

Ronsku commented 1 year ago

Update from CC 3.8.0, vs latest CC2 version 2.4.11.

Very Stripped 2D Build in 3.8.0: image

I think things were moved out from the bundle, but the bundle is still relatively the same size or slightly bigger? Compared to version 3.7.2: 3.7.2: CC bundle is 1,806 KB 3.8.0: CC bundle is 1,825 KB while it looks like Spine has even been stripped out and adds an additional 701 KB?! image

2.4.11 while CC2 stays at 991 KB

Here are the statistics of just the CC bundle between CC2 and CC3, without taking into consideration the 701 KB Spine file.

image

I'm getting really worried getting stuck in legacy CC2 forever or having to look for alternatives, which I really wouldn't like to do ๐Ÿ˜จ?!

Ronsku commented 1 year ago

Sorry, we adjusted this issue plan to milestrone 3.9

Praying for 3.9 with everything I have! ๐Ÿ™

jareguo commented 11 months ago

We will continue to optimize the engine's packages in 3.8.x. But it's really hard to fully optimize to 2.x level

PPpro commented 11 months ago

3.7.2: CC bundle is 1,806 KB 3.8.0: CC bundle is 1,825 KB while it looks like Spine has even been stripped out and adds an additional 701 KB?!

the spine asm.js module is a fallback for spine wasm module, which is another part of the added package size.
we've provided an build option to cull the asm.js module to reduce package size, please have a try @Ronsku image

Ronsku commented 11 months ago

@jareguo Thank you so much, I believe its a big challenge, but 1.9Mb engine size + features like spine is so big for smaller games, where you would like to ensure a fast loading.

Compared to the size of for example pixi.js v6.4.2 is 479.1 kB (minified), and 125.6 kB when compressed using GZIP. The latest versions even slightly smaller.

That makes CC2.4.8 about 2.8x bigger and CC3.8.0 5x bigger than pixi.js using GZIP. I understand they are very different, but it just feels so unfortunate that the difference is so massive, when I otherwise love Cocos Creator ๐Ÿ˜ž.

the spine asm.js module is a fallback for spine wasm module, which is another part of the added package size.

Thanks for your message @PPpro, here are the results in CC 3.8.0:

Without checked "Cull Engine Asm.js Module":

With checked "Cull Engine Asm.js Module":

Engine itself in both cases adding an additional whopping 1.9Mb uncompressed size. Massive for 2D use ๐Ÿ˜“.

Ronsku commented 6 months ago

Just to update this issue. I ran similar tests on 3.8.1 and 3.8.2 as my above 3.8.0 output.

minggo commented 1 month ago

The goal for 3.8.4 is to make the package size less or equal 3.8.0, and we will continue reducing package size in all versions.