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

[test] Check the engine size on web platform after removing @serializable decorator

Open dumganhar opened this issue 1 year ago • 2 comments

Original size: 4,770,578 bytes Remove all serializable decorator: 4,694,569 bytes, diff size: 76009 bytes (76KB)

dumganhar avatar Sep 21 '22 06:09 dumganhar

Writing serialization code manually like the following:

public archive (ar: any) {
    super.archive(ar);
    ar.archive('_projection', this._projection);
    ar.archive('_priority', this._priority);
    ar.archive('_fov', this._fov);
    ar.archive('_fovAxis', this._fovAxis);
    ar.archive('_orthoHeight', this._orthoHeight);
    ar.archive('_near', this._near);
    ar.archive('_far', this._far);
    ar.archive('_color', this._color);
    ar.archive('_depth', this._depth);
    ar.archive('_stencil', this._stencil);
    ar.archive('_clearFlags', this._clearFlags);
    ar.archive('_rect', this._rect);
    ar.archive('_aperture', this._aperture);
    ar.archive('_shutter', this._shutter);
    ar.archive('_iso', this._iso);
    ar.archive('_screenScale', this._screenScale);
    ar.archive('_visibility', this._visibility);
    ar.archive('_targetTexture', this._targetTexture);
}

will make the js code smaller.

dumganhar avatar Sep 22 '22 01:09 dumganhar

javascript primitive type is value type rather than reference type. How to assign the member variables?

Perhaps, just passing owner object to ar function and set the property according property name.

ar.archive('_projection', this); // this is owner

Invoking owner[key] = balabala; to set the value.

dumganhar avatar Sep 22 '22 03:09 dumganhar