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

[v3.8.6] Mark some properties as @dontmangle. #18160

Open
wants to merge 12 commits into
base: v3.8.6
Choose a base branch
from

Conversation

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

Copy link

github-actions bot commented Jan 11, 2025

⚠️ Package size ⤴ 76 bytes, old: 5241181, new: 5241257

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -21283,8 +21283,13 @@
         /**
          * @internal
          */
         _objFlags: number;
+        /**
+         * @dontmangle
+         * NOTE: _name is a serializable property set by `CCClass.fastDefine`,
+         * so it should not be mangled while `mangleProtected` is true in `<<ProjectRoot>>/engine-mangle-config.json`.
+         */
         protected _name: string;
         constructor(name?: string);
         /**
          * @en The name of the object.
@@ -24602,8 +24607,16 @@
         /**
          * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
          */
         _updateSiblingIndex(): void;
+        /**
+         * @dontmangle
+         * NOTE: the protected method `_instantiate` is invoked by dynamically without type information.
+         * See `instantiate` in cocos/serialization/instantiate.ts.
+         * ```ts
+         * clone = original._instantiate(null, true); // original is any, so _instantiate should not be mangled.
+         * ```
+         */
         protected _instantiate(cloned?: Node | null, isSyncedNode?: boolean): Node;
         protected _onHierarchyChangedBase(oldParent: this | null): void;
         protected _onPreDestroyBase(): boolean;
         protected _onSiblingIndexChanged?(siblingIndex: number): void;
@@ -25815,8 +25828,16 @@
          * 此方法将在第一次实例化预制件之前自动调用,<br/>
          * 但是您可以在脚本中修改原始预制数据后重新调用以刷新创建功能。
          */
         compileCreateFunction(): void;
+        /**
+         * @dontmangle
+         * NOTE: the protected method `_instantiate` is invoked by dynamically without type information.
+         * See `instantiate` in cocos/serialization/instantiate.ts.
+         * ```ts
+         * clone = original._instantiate(null, true); // original is any, so _instantiate should not be mangled.
+         * ```
+         */
         protected _instantiate(): Node;
         initDefault(uuid?: string): void;
         validate(): boolean;
         onLoaded(): void;
@@ -64038,9 +64059,20 @@
              */
             clear(): void;
             protected searchKeyframe(time: number): number;
             protected setKeyframes(times: number[], values: TKeyframeValue[]): void;
+            /**
+             * Times are always sorted and 1-1 correspond to values.
+             * @dontmangle
+             * NOTE: _times is a serializable property set by `CCClass.fastDefine`,
+             * so it should not be mangled while `mangleProtected` is true in `<<ProjectRoot>>/engine-mangle-config.json`.
+             */
             protected _times: number[];
+            /**
+             * @dontmangle
+             * NOTE: _values is a serializable property set by `CCClass.fastDefine`,
+             * so it should not be mangled while `mangleProtected` is true in `<<ProjectRoot>>/engine-mangle-config.json`.
+             */
             protected _values: TKeyframeValue[];
         }
         /**
          * @engineInternal

@dumganhar dumganhar marked this pull request as draft January 11, 2025 14:00
@dumganhar dumganhar changed the title [v3.8.6] [TEST] Optimize code size, mangle protected properties. [v3.8.6] Fix some type issues and mark some properties as @dontmangle. Jan 14, 2025
@dumganhar dumganhar marked this pull request as ready for review January 15, 2025 09:04
@dumganhar dumganhar requested a review from minggo January 15, 2025 09:04
protected _times: number[] = [];

/** @dontmangle */
protected _values: TKeyframeValue[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

protected member variable will be mangled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The file engine-mangle-config.json supports to control whether to mangle protected properties globally, its default value is false which means protected properties will not be mangled. But if developers set it to true, then all protected properties will be mangled too. The file format is :

{
	"common": {
	    "mangleProtected": false, // <------- here
	    "mangleList": [
	    	"MyClass2",
	    	"MyClass.foo",
	    	"MyClass.getBar"
	    ],
	    "dontMangleList": [
	        "BaseFactory",
	        "Slot",
	        "MyClass.hello"
	    ]
	},
	"web-mobile": {
		"extends": "common",
		"mangleList": [
			"MyClass3",
			"MyClass4.haha",
			"MyClass4.w111uwu"
		],
		"dontMangleList": [
			"MyClass5.skldjfl"
		]
	}
}

So if developer set mangleProtected to true, some properties are set by cc.fastDefine to mark them as serializable, so they should not be mangled. In this case, we should make sure some properties in engine should not be mangled by jsdoc tag @dontmangle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example:

CCClass.fastDefine('cc.AnimationCurve', AnimationCurve, {
    _curve: null, // <---- the protected property _curve should not be mangled.
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. If so, then how to determine if a protected variable can be mangled or not? What i mean is how to know if need to add @@dontmangle for protected variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to review the code to decide. So the mangleProtected is disabled (false) by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

Need to review the code to decide.

Is there a simple rule to determine it? If not, then it will be hard to maintain the codes. And how to make sure it work or not, is there a CI to check it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, we haven't enable CI to run the feature of mangleProperties. I will discuss with QA team after editor is updated.

@dumganhar dumganhar changed the title [v3.8.6] Fix some type issues and mark some properties as @dontmangle. [v3.8.6] Mark some properties as @dontmangle. Jan 15, 2025
@dumganhar dumganhar requested a review from minggo January 15, 2025 15:01
@dumganhar
Copy link
Contributor Author

Package size ⤴ 76 bytes

Because the private property AnimationCurve._curve should not be mangled since it's a serializable property used by cc.fastDefine.

@dumganhar
Copy link
Contributor Author

@minggo I added some comment for the API being marked as @dontmangle and reverted changes in component.ts

@dumganhar dumganhar marked this pull request as draft January 17, 2025 03:19
@dumganhar dumganhar marked this pull request as ready for review January 17, 2025 03:25
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