Skip to content

[v3.8.6] Add freezeColor internal method to reduce code size.#18162

Merged
minggo merged 1 commit into
cocos:v3.8.6from
dumganhar:386-opt-size-color-2
Jan 13, 2025
Merged

[v3.8.6] Add freezeColor internal method to reduce code size.#18162
minggo merged 1 commit into
cocos:v3.8.6from
dumganhar:386-opt-size-color-2

Conversation

@dumganhar

Copy link
Copy Markdown
Contributor

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@github-actions

Copy link
Copy Markdown

👍 Package size ⤵ -136 bytes, old: 5270176, new: 5270040

Interface Check Report

This pull request does not change any public interfaces !

@dumganhar dumganhar requested a review from minggo January 13, 2025 02:13
Comment thread cocos/core/math/color.ts
public static BLUE = freezeColor(0, 0, 255, 255);
public static CYAN = freezeColor(0, 255, 255, 255);
public static MAGENTA = freezeColor(255, 0, 255, 255);
public static YELLOW = freezeColor(255, 255, 0, 255);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just assign Object.freeze to a variable? Such as

const freezeColor = Object.freeze;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we could, I didn't test that.
This depends on whether the implementation of Object.freeze uses this object since we change this object by const freezeColor = Object.freeze.

For safety, it's better to use const freezeColor = Object.freeze.bind(Object);.

@dumganhar dumganhar Jan 13, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking a while, I think we should not use const freezeColor = Object.freeze since that will generate more code.

public static BLUE = freezeColor(new Color(0, 0, 255, 255)); 

will be mangled to

Color.BLUE = aa(new Color(0, 0, 255, 255));

while using function

public static BLUE = freezeColor(0, 0, 255, 255);

will be mangled to

Color.BLUE = aa(0, 0, 255, 255); // shorter and without new Color(...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@minggo minggo merged commit aa06696 into cocos:v3.8.6 Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants