Safe cutting of modules

I have the following question:
Is there some way to reduce the weight of the engine file by cutting out the modules I’m not using?

Is there already a ready-made solution? If not, then what would you advise to do it more efficiently and with less risk of damaging the required modules and overall engine performance?

I’m not sure how many KBs you want to save or how important thouse would be, but yes, you could.

Download the source code, insert your game’s code, import only the modules you need, and build all together.

Just in application.js, the first 120 lines are imports that you may or may not need.

You could also use a glsl compressor to compress the chunks for the shaders. Same for other strings.

Good luck.


Will posted an image of what modules take up the space:

Bear in mind that the Engine size after gzipped for transport is 338KB.

You can fork the engine and edit the file: (you may prefer to do this in the latest ‘stable’ release branch of 1.54 right now)

In theory (I’ve not tried this), you can remove component/systems that you don’t want to use such as the UI module (which is pretty large).

However, you are talking about 10s of KB after gzip so unless you are looking for a very lean engine and scoped functionality, I’m not sure if you are going to get the gain you want?

Edit: I remember that you were looking at making Playable Ads so I can see why you want this. I would be interested to see how much it can be compressed on top of the compression option:


Got it, then I’ll test this method and let you know.
Thank you so much for the detailed answer. As always :slightly_smiling_face:

Hi, thanks for the info.

Can you recommend any glsl compressor? The one which will be compatible with playcanvas shaders chunks format (template literals)?
Or do i better extend rollup.config.js to remove comments, extra tabs and spaces, minify local vars, etc. ?

I cant, but anyway it may not work with the chunk system, only with full shader xode. This is because if it renames functions or variables, each chunk may not be compatible with the rest anymore

Ok, make sense.

Anyway, i guess removing of comments and spaces - will already save a lot of space.

I believe that code is already minified in the min.js builds

Please see rollup.config.js:

@yaustar Hi again. Here is a small report on this thread.

I removed some of the modules that I don’t use in one specific project of mine (animations, a large part of the UI, legacy components, collision, sprites and some others) and thereby saved almost 300kb. Theoretically, if completely abandon the Playcanvas UI (sad sacrifice for the weight of the engine :smiling_face_with_tear:) in favor of simple HTML, we can save another ±100kb.
If we use the lz4.js compressor together with this, it will save another 500kb.
In the end, I got a fully working project with an engine of about 500kb, which gives even more space for logic and assets in Playable Ads.

I hope it will also be useful to others looking for ways to reduce the critical weight of their project.

1 Like

Yeah, the UI system is pretty heavy :sweat_smile:

How large is the full engine after LZ4?

I must have expressed myself badly. I meant that the engine file itself weighs 500kb (not the project + engine). However, if we completely remove the UI, it can weigh about 400kb

Ah, how does that compare to the size of the complete by itself after LZ4? I’m interested in the size difference of the engine after compression :slight_smile:

This is after compression with lz4 (400-500kb). Without compression, it weighs 0.9-1 MB

Edit: This is specifically for me, since I do not use some components other than UI (animations, collision, sprites). If someone wants to cut out components that they are not using in their particular project, then the weight may vary slightly

Yes, but how much smaller was it compared to not doing any of the cutting?

ie Without the compression, the full engine is 1.2-1.3MB. How big is the full engine after compression?

Edit: It looks like it is 713KB after LZ4 compression

So you are saving 200-300KB by cutting modules which is impressive!

Yeah, that’s right