-
Notifications
You must be signed in to change notification settings - Fork 10
refactor: enhance ByteBuffer.get performance #25
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
Conversation
|
@gxcsoccer, thanks for your PR! By analyzing the history of the files in this pull request, we identified @fengmk2, @dead-horse and @pmq20 to be potential reviewers. |
|
前后 benchmark 对比呢? |
| }; | ||
|
|
||
| ByteBuffer.prototype.get = function (index, length) { | ||
| if (index instanceof Buffer || Array.isArray(index)) { // get (byte[] dst, int offset, int length) |
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.
这个判断比较耗时,把它挪到后面去,在 hessian.js 里大部分情况是 get() 或者 get(index)
|
|
ping @fengmk2 |
lib/byte.js
Outdated
| this.checkArraySize(dst.length, offset, length); | ||
| this.checkForUnderflow(length); | ||
|
|
||
| if (is.buffer(dst)) { |
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.
直接用 Buffer.isBuffer() 吧,就不需要引入 is-type-of 了
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.
+1 改掉这个
| // old get() x 2,234,273 ops/sec ±1.45% (90 runs sampled) | ||
| // new get() x 24,872,342 ops/sec ±2.13% (89 runs sampled) | ||
| // old get(index) x 2,339,452 ops/sec ±0.81% (93 runs sampled) | ||
| // new get(index) x 25,533,534 ops/sec ±0.84% (100 runs sampled) |
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.
这性能优化有点吊。。。一个数量级。
|
@gxcsoccer 去掉 is-type-of 的依赖,你自己合并发布新版本。 |
|
👏 赞 没想到 |
|
@fengmk2 加个权限 |
|
@gxcsoccer done |
调整一下 ByteBuffer.get 参数判断的顺序