Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC3 Engine Code double size from CC2 #10354

Open
Ronsku opened this issue Mar 15, 2022 · 40 comments
Open

CC3 Engine Code double size from CC2 #10354

Ronsku opened this issue Mar 15, 2022 · 40 comments
Assignees
Labels
Module: Build Project build related Needs Triage Needs to be assigned by the team Optimization Enhancement in performance, usability, stability etc P1 Must be finished in the milestone
Milestone

Comments

@Ronsku
Copy link

Ronsku commented Mar 15, 2022

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
Copy link
Contributor

minggo commented Mar 24, 2022

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

@Ronsku
Copy link
Author

Ronsku commented Mar 25, 2022

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

@minggo
Copy link
Contributor

minggo commented Mar 25, 2022

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
Copy link
Author

Ronsku commented Mar 28, 2022

@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
Copy link
Contributor

minggo commented Mar 28, 2022

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

@pandamicro pandamicro added this to the V3.6 milestone Mar 28, 2022
@pandamicro pandamicro added Optimization Enhancement in performance, usability, stability etc Module: Build Project build related labels Mar 28, 2022
@Ronsku
Copy link
Author

Ronsku commented Apr 2, 2022

@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
Copy link
Author

Ronsku commented May 11, 2022

@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
Copy link
Contributor

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
Copy link
Author

Ronsku commented May 12, 2022

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
Copy link

@holycanvas Does this help in native env as well?

@Ronsku
Copy link
Author

Ronsku commented Jun 3, 2022

@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
Copy link
Author

Ronsku commented Jun 3, 2022

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
Copy link
Author

Ronsku commented Jun 3, 2022

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

Non-GZIP
image
image
image

GZIP:ed
image
image
image

@Ronsku
Copy link
Author

Ronsku commented Jun 4, 2022

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

@shrinktofit
Copy link
Contributor

shrinktofit commented Jun 7, 2022

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

@Ronsku
Copy link
Author

Ronsku commented Jun 7, 2022

@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
Copy link
Contributor

shrinktofit commented Jun 7, 2022

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

@Ronsku
Copy link
Author

Ronsku commented Jun 14, 2022

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

@pandamicro
Copy link
Contributor

pandamicro commented Jun 15, 2022

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 #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 pandamicro added the P1 Must be finished in the milestone label Jun 15, 2022
@pandamicro pandamicro removed this from the V3.6 milestone Jun 15, 2022
@PPpro PPpro removed this from the V3.7 milestone Dec 5, 2022
@Ronsku
Copy link
Author

Ronsku commented Feb 2, 2023

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
Copy link
Author

Ronsku commented Feb 2, 2023

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
Copy link
Author

Ronsku commented Mar 1, 2023

@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 #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
Copy link
Contributor

minggo commented Mar 2, 2023

@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
Copy link
Author

Ronsku commented Mar 24, 2023

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

@PPpro
Copy link
Contributor

PPpro commented May 6, 2023

Sorry, we adjusted this issue plan to milestrone 3.9

@PPpro PPpro modified the milestones: V3.8, V3.9 May 6, 2023
@Ronsku
Copy link
Author

Ronsku commented May 19, 2023

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
Copy link

麻烦一起看看3.x各个版本之后的包体增加,应该是相同的问题。
https://forum.cocos.org/t/topic/145082

@Ronsku
Copy link
Author

Ronsku commented Jun 26, 2023

麻烦一起看看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.

@pandamicro pandamicro mentioned this issue Jun 30, 2023
7 tasks
@jareguo
Copy link
Contributor

jareguo commented Jun 30, 2023

@Ronsku
Copy link
Author

Ronsku commented Aug 6, 2023

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
Copy link
Author

Ronsku commented Aug 6, 2023

Sorry, we adjusted this issue plan to milestrone 3.9

Praying for 3.9 with everything I have! 🙏

@jareguo
Copy link
Contributor

jareguo commented Sep 15, 2023

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
Copy link
Contributor

PPpro commented Sep 20, 2023

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
Copy link
Author

Ronsku commented Sep 20, 2023

@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":

  • Both .wasm and .js are loading on web assembly supported browser.
  • Adding 1124Kb uncompressed size
    image

With checked "Cull Engine Asm.js Module":

  • Only .wasm loading
  • Adding 406Kb uncompressed size.
    image

Engine itself in both cases adding an additional whopping 1.9Mb uncompressed size. Massive for 2D use 😓.

@jareguo jareguo added the Needs Triage Needs to be assigned by the team label Oct 24, 2023
@jareguo jareguo assigned minggo and unassigned PPpro Oct 24, 2023
@Ronsku
Copy link
Author

Ronsku commented Feb 17, 2024

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
Copy link
Contributor

minggo commented Aug 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: Build Project build related Needs Triage Needs to be assigned by the team Optimization Enhancement in performance, usability, stability etc P1 Must be finished in the milestone
Projects
Status: Todo
Development

No branches or pull requests

9 participants