-
Notifications
You must be signed in to change notification settings - Fork 29
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
[WIP] refactor: enhance decode performance #74
base: master
Are you sure you want to change the base?
Conversation
@gxcsoccer, thanks for your PR! By analyzing the history of the files in this pull request, we identified @dead-horse and @fengmk2 to be potential reviewers. |
@@ -92,7 +95,7 @@ proto.handleType = function(type, val, withType) { | |||
* @api public | |||
*/ | |||
proto.readNull = function () { | |||
this._checkLabel('readNull', 'N'); |
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.
如果把 readNull,readInt 等这种 api 都变成私有的,只暴露 read,那 checkLabel 这个是没必要的
@@ -299,7 +306,7 @@ utils.addByteCodes(BYTE_CODES, [ | |||
proto.readDate = function () { | |||
var code = this.byteBuffer.get(); | |||
if (code === 0x4a) { | |||
return new Date(utils.handleLong(this.byteBuffer.getLong())); | |||
return new Date(this.byteBuffer.getLong().toNumber()); |
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.
针对 date,直接 toNumber 就好了
head = this.byteBuffer.get(); | ||
l = utils.lengthOfUTF8(head); | ||
this.byteBuffer.skip(l - 1); | ||
ch = this.byteBuffer.get(); |
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.
这个改完会有多大性能提升?
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.
少了一次循环,我之前有测,==
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.
优化前
hessian2 decode: string x 1,251,833 ops/sec ±1.35% (86 runs sampled)
优化后
hessian2 decode: string x 1,482,684 ops/sec ±1.29% (85 runs sampled)
这俩组数据要在同一台机器 && Node.js version 上跑才有意义。我试一下我的机器 && node 8-pre |
@gxcsoccer 同一台机器,同样的 node 版本下:
|
@@ -47,7 +47,10 @@ proto._addRef = function (obj) { | |||
* @api public | |||
*/ | |||
proto.init = function (buf) { | |||
this.byteBuffer = ByteBuffer.wrap(buf); | |||
this.byteBuffer._bytes = buf; |
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.
为何要使用这种私有 api?
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.
this.byteBuffer.reset(buf)
这种不是更好?
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.
reset 没有入参,这里是 WIP,还不是最终版本,先找到优化点,后面可以针对性的对 api 做调整
ByteBuffer.prototype.reset = function () {
this._offset = 0;
};
@gxcsoccer 比之前的 js 版本优化多少?加上对比 |
ci 加上 node 7 |
Codecov Report
@@ Coverage Diff @@
## master #74 +/- ##
==========================================
- Coverage 96.09% 95.51% -0.58%
==========================================
Files 7 7
Lines 1076 1093 +17
Branches 202 204 +2
==========================================
+ Hits 1034 1044 +10
- Misses 42 49 +7
Continue to review full report at Codecov.
|
@pmq20 你跑的时候 byte 还没有合并,现在再跑跑试试 |
优化前
优化后
|
number 和 string 的优化主要来自于 byte.get node-modules/byte#25 |
|
💯 确实性能和 fast hessian2 差不多了 |
@gxcsoccer 这周忙完继续搞这个,最近 rpc 比较多压力。 |
初步优化了下 number, date 和 string,性能和孝达的 fast hessian2 差不多了