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

use const enum type in engine to reduce engine size

Open PPpro opened this issue 2 years ago • 4 comments

image

Need to confirm whether there is any use of value to reverse query the key of the enum object in the engine, if not, we can consider changing the entire amount to const enum

PPpro avatar Jun 02 '23 02:06 PPpro

I don't quite understand this issue. It seems like a coding style issue. May modify all engine codes.

minggo avatar Apr 03 '24 03:04 minggo

@minggo on the left of captured image is the source code of ts, and the right one is the compiled output

while we use const enum, the output js is of much more smaller package size. It's not the matter of coding style but the engine size.

PPpro avatar Apr 08 '24 00:04 PPpro

WeChat085c82d76a93ea057f918db91ae667a0

But I found that const enum will be optimized like the above.

I think the enums in the internal modules could use const enums safely while the public enum should not since it will break the compatibility. Yes, const enum will may package size smaller. Perhaps, we need a switch to open/close this feature.

dumganhar avatar Apr 08 '24 02:04 dumganhar