cocos-engine icon indicating copy to clipboard operation
cocos-engine copied to clipboard

CC3 Engine Code double size from CC2

Open Ronsku opened this issue 3 years ago • 40 comments
trafficstars

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.

Ronsku avatar Mar 15 '22 19:03 Ronsku

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

minggo avatar Mar 24 '22 07:03 minggo

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

Ronsku avatar Mar 25 '22 01:03 Ronsku

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?

minggo avatar Mar 25 '22 03:03 minggo

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

Ronsku avatar Mar 28 '22 08:03 Ronsku

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

minggo avatar Mar 28 '22 09:03 minggo

@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 avatar Apr 02 '22 23:04 Ronsku

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

Ronsku avatar May 11 '22 12:05 Ronsku

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

SantyWang avatar May 12 '22 08:05 SantyWang

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 :)

Ronsku avatar May 12 '22 11:05 Ronsku

@holycanvas Does this help in native env as well?

smitpatel88 avatar Jun 02 '22 03:06 smitpatel88

@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 avatar Jun 03 '22 08:06 Ronsku

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 avatar Jun 03 '22 10:06 Ronsku

Some Google Lighthouse stats, on a game with most features removed 😬

Non-GZIP image image image

GZIP:ed image image image

Ronsku avatar Jun 03 '22 23:06 Ronsku

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

Ronsku avatar Jun 04 '22 00:06 Ronsku

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

shrinktofit avatar Jun 07 '22 08:06 shrinktofit

@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 😞

Ronsku avatar Jun 07 '22 09:06 Ronsku

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

shrinktofit avatar Jun 07 '22 09:06 shrinktofit

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

Ronsku avatar Jun 14 '22 10:06 Ronsku

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 ?

pandamicro avatar Jun 15 '22 14:06 pandamicro

@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?

Ronsku avatar Jul 02 '22 14:07 Ronsku

@holycanvas Is this ready for 3.6 already

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

SantyWang avatar Jul 09 '22 06:07 SantyWang

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)

Ronsku avatar Aug 10 '22 14:08 Ronsku

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.

SantyWang avatar Aug 19 '22 03:08 SantyWang

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 avatar Feb 02 '23 13:02 Ronsku

Update on CC 3.7.0

By Removing

  • 2D Physics System
  • 2D Intersection Algorithms
  • 2D Particle System

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 avatar Feb 02 '23 13:02 Ronsku

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

Ronsku avatar Mar 01 '23 11:03 Ronsku

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

minggo avatar Mar 02 '23 02:03 minggo

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

Ronsku avatar Mar 24 '23 09:03 Ronsku

Sorry, we adjusted this issue plan to milestrone 3.9

PPpro avatar May 06 '23 03:05 PPpro

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!

Ronsku avatar May 19 '23 13:05 Ronsku