Skip to content

Optimize code size for draw-batch.ts and batcher-2d.ts, remove needless setter/getter.#18238

Merged
minggo merged 2 commits into
cocos:v3.8.6from
dumganhar:386-opt-size-drawbatch
Jan 24, 2025
Merged

Optimize code size for draw-batch.ts and batcher-2d.ts, remove needless setter/getter.#18238
minggo merged 2 commits into
cocos:v3.8.6from
dumganhar:386-opt-size-drawbatch

Conversation

@dumganhar

Copy link
Copy Markdown
Contributor

Re: #18222

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.

@dumganhar dumganhar requested a review from minggo January 22, 2025 14:00
@github-actions

github-actions Bot commented Jan 22, 2025

Copy link
Copy Markdown

👍 Package size ⤵ -1220 bytes, old: 5226328, new: 5225108

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -61331,15 +61331,10 @@
             allocateChunk(vertexCount: number, indexCount: number): _cocos_2d_renderer_static_vb_accessor__StaticVBChunk | null;
             recycleChunk(chunk: _cocos_2d_renderer_static_vb_accessor__StaticVBChunk): void;
             static generateID(): number;
         }
+        /** @mangle */
         export class _cocos_2d_renderer_draw_batch__DrawBatch2D {
-            get inputAssembler(): gfx.InputAssembler | null;
-            set inputAssembler(ia: gfx.InputAssembler | null);
-            get descriptorSet(): gfx.DescriptorSet | null;
-            set descriptorSet(ds: gfx.DescriptorSet | null);
-            get visFlags(): number;
-            set visFlags(vis: number);
             get passes(): renderer.Pass[];
             get shaders(): gfx.Shader[];
             model: renderer.scene.Model | null;
             texture: gfx.Texture | null;
@@ -61347,8 +61342,11 @@
             useLocalData: Node | null;
             isStatic: boolean;
             textureHash: number;
             samplerHash: number;
+            visFlags: number;
+            inputAssembler: gfx.InputAssembler | null;
+            descriptorSet: gfx.DescriptorSet | null;
             destroy(ui: _cocos_2d_renderer_i_batcher__IBatcher): void;
             clear(): void;
             fillPasses(mat: Material | null, dss: gfx.DepthStencilState | null, dssHash: number, patches: Readonly<renderer.IMacroPatch[] | null>): void;
         }

@dumganhar

Copy link
Copy Markdown
Contributor Author

@cocos-robot run test cases

@github-actions

Copy link
Copy Markdown

@dumganhar, Please check the result of run test cases:

Task Details

@github-actions

Copy link
Copy Markdown

@dumganhar, Please check the result of run test cases:

Task Details

private declare _localData: Float32Array | null;

public get descriptorSet (): DescriptorSet | null {
public getDescriptorSet (): DescriptorSet | null {

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.

Why have to change it?

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.

It's because we're using babel to compile ts to js.
babel has its own getter/setter accessor definition which could not be understood by terser minifier.

See this issue: terser/terser#322

Since LocalDescriptorSet is an internal module, change the get descriptSet to function getDescriptorSet is fine for us.

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, it is better to add a description.

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.

Added comments.

@minggo minggo merged commit 8de922e into cocos:v3.8.6 Jan 24, 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