-
Notifications
You must be signed in to change notification settings - Fork 2k
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
optimize json merging #6716
Conversation
# 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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
拆分 json 的逻辑很简单,只是提前做了类的查找
cocos2d/core/3d/particle/curve.ts
Outdated
export class AnimationCurve { | ||
@property({ | ||
default: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个好像不能改来着,之前改了,3d粒子就没动画了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我确认了一下目前的数据还是对的。粒子能播放。可能因为是 ES6 的类。
gulp/util/inline-prop.js
Outdated
} | ||
|
||
exports.inlineEnum = function (filename) { | ||
if (filename.endsWith('.js') || filename.endsWith('.ts')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是全部js都会替换么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有写指定注释的才会替换
预加载的解析依赖的逻辑可能得调整下,不过问题不大 |
# Conflicts: # cocos2d/core/asset-manager/deserialize.js
减小合并后的 json 体积,json 越大效果越明显, Asset Bundle 整个合并的话能减小 5% - 20%。
因为只对合并做优化,不合并的话整个项目而言包体只是略微减小。
结合前一个 PR,目前大场景或者合并后的大 json 体积最多能优化到原先的 25%。
对整个项目来说所有 json 的体积差不多能优化 30%。