8000 optimize json merging by jareguo · Pull Request #6716 · cocos/cocos-engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

optimize json merging #6716

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

Merged
merged 26 commits into from
Jun 23, 2020
Merged

optimize json merging #6716

merged 26 commits into from
Jun 23, 2020

Conversation

jareguo
Copy link
Contributor
@jareguo jareguo commented May 19, 2020

减小合并后的 json 体积,json 越大效果越明显, Asset Bundle 整个合并的话能减小 5% - 20%。
因为只对合并做优化,不合并的话整个项目而言包体只是略微减小。

结合前一个 PR,目前大场景或者合并后的大 json 体积最多能优化到原先的 25%。
对整个项目来说所有 json 的体积差不多能优化 30%。

Compare with #6645 Before After v1 (%) After v2 (%)
QP 项目 json 627,280 bytes - 625,330 bytes (-0.3%)
- zip 452,179 bytes - 451,350 bytes (-0.18%)
QP 项目 resources bundle json (merge all) 202,329 bytes - 192,669 bytes (-4.8%)
- zip 39,331 bytes - 39,118 bytes (-0.54%)
example all jsons 1,786,707 bytes 1,789,210 bytes 1,784,000 bytes (-0.15%)
- zip 565,296 bytes 565,431 bytes 564,962 bytes (-0.06%)
example main bundle (merge all json) 1,170,662 bytes 946,900 bytes (-19.1%) 942,140 bytes (-19.5%)
- zip 256,955 bytes 207,543 bytes (-19.2%) 207,298 bytes (-19.3%)

jareguo added 17 commits May 4, 2020 16:30
# Conflicts:
#	cocos2d/core/asset-manager/pipeline.js
# Conflicts:
#	cocos2d/core/load-pipeline/pack-downloader.js
#	cocos2d/core/load-pipeline/unpackers.js
#	cocos2d/core/load-pipeline/uuid-loader.js
#	cocos2d/core/platform/deserialize.js
#	test/qunit/unit-es5/test-pack-downloader.js
#	test/qunit/unit-es5/test-pack-unpack.js
# Conflicts:
#	cocos2d/core/asset-manager/deserialize.js
#	cocos2d/core/asset-manager/pack-manager.js
#	cocos2d/core/platform/deserialize-compiled.ts
#	cocos2d/core/platform/deserialize.js
#	gulp/util/utils.js
#	test/qunit/unit/test-serialize-compiled.js
* @typescript
* isSceneObj(json: any): boolean
*/
isSceneObj: function (json) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

简化了反序列化过程中的类型查找逻辑


if (Array.isArray(json)) {

json = unpackJSONs(json, cc._MissingScript.safeFindClass);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@holycanvas 在这里插入了 json 拆分的逻辑,大 json 下载后就会通过这个 API 拆分成小 json

lookupClasses(data, options);
cacheMasks(data);
if (!preprocessed) {
lookupClasses(data, false, options.classFinder);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

如果 json 未拆分过(单独的资源),则走完整的类型查找流程

throw new Error(cc.debug.getError(5304, data[File.Version]));
}
lookupClasses(data, true, classFinder);
cacheMasks(data);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

拆分 json 的逻辑很简单,只是提前做了类的查找

@jareguo jareguo requested a review from SantyWang June 1, 2020 03:12
@SantyWang SantyWang changed the base branch from master to v2.4.1 June 3, 2020 03:33
export class AnimationCurve {
@property({
default: [],
Copy link
Contributor

Choose a reason for hiding this comment

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

这个好像不能改来着,之前改了,3d粒子就没动画了

Copy link
Contributor Author
@jareguo jareguo Jun 17, 2020

Choose a reason for hiding this comment

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

我确认了一下目前的数据还是对的。粒子能播放。可能因为是 ES6 的类。

}

exports.inlineEnum = function (filename) {
if (filename.endsWith('.js') || filename.endsWith('.ts')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

这是全部js都会替换么?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

有写指定注释的才会替换

@SantyWang
Copy link
Contributor

预加载的解析依赖的逻辑可能得调整下,不过问题不大

# Conflicts:
#	cocos2d/core/asset-manager/deserialize.js
@jareguo jareguo merged commit c025fa7 into cocos:v2.4.1 Jun 23, 2020
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
0