-
Notifications
You must be signed in to change notification settings - Fork 2k
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] Use array.forEach instead of for of
to optimize code size
#18112
Conversation
👍 Package size ⤵ -1216 bytes, old: 5280335, new: 5279119Interface Check ReportThis pull request does not change any public interfaces ! |
for of
and for index
.for of
and for index
, forEach
.
@cocos-robot run test cases |
} | ||
this._cameras.splice(0); | ||
}); | ||
this._cameras.length = 0; |
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.
Use this._cameras.length = 0;
instead of this._cameras.splice(0);
to improve a little performance.
@dumganhar, Please check the result of
Task Details
|
@dumganhar, Please check the result of
Task Details
|
for of
and for index
, forEach
.for of
to optimize code size
this.optimizedKeys = new Array<geometry.OptimizedKey>(); // the i-th optimezed key stores coefficients of [i,i+1] segment in the original curve,so if the time of last key of the original key is 1,the last key won't be kept in the opt curve. | ||
this.integral = new Array<number>(); // the integral of the curve between 0 and corresponding key,the i-th integral corresponds to the i+1-th key in optimizedKeys (because the integral of the first key is always zero,the first key won't be stored) | ||
this.optimizedKeys = []; // the i-th optimezed key stores coefficients of [i,i+1] segment in the original curve,so if the time of last key of the original key is 1,the last key won't be kept in the opt curve. | ||
this.integral = []; // the integral of the curve between 0 and corresponding key,the i-th integral corresponds to the i+1-th key in optimizedKeys (because the integral of the first key is always zero,the first key won't be stored) |
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.
[]
contains less code than new Array()
.
@cocos-robot run test cases |
@dumganhar, Please check the result of
Task Details
|
@dumganhar, Please check the result of
Task Details
|
… a PR ( cocos#18112 ) in v3.8.6.
Babel compiles
to
JSBenchMark ( Array Iteration)
Paste the following test code to https://jsbench.me/
Setup Javascript
for of
for babel iterator
for index
forEach
Result (Array Iteration)
JSBenchMark ( Object Iteration)
Setup Javascript
[object] for in
[object] for in and check whether own property
[object] for index and Object.keys
[object] for of
Result (Object Iteration)
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: